Skip to content

Commit 9b2670c

Browse files
authored
Update and lock swift-syntax version to latest snapshot while fixing errors/warnings (#2)
- Updated and locked swift-syntax version - Fixed deprecation warnings - Fixed compilation errors - Fixed tests ----- Couldn't fix AddAsync/AddCompletionHandler macros, they are called multiple times and produce diagnostic errors
1 parent e45eafd commit 9b2670c

28 files changed

+115
-73
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ let package = Package(
1515
dependencies: [
1616
.package(
1717
url: "https://github.com/apple/swift-syntax.git",
18-
from: "509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-25-b"),
18+
exact: "509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-08-15-a"
19+
),
1920
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
2021
.package(url: "https://github.com/SwiftPackageIndex/SPIManifest.git", from: "0.12.0"),
2122
],

Sources/MacroToolkit/Attribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public struct Attribute {
1313
/// Creates a new attribute with the given name.
1414
public init(named name: String) {
1515
_syntax = AttributeSyntax(
16-
attributeName: SimpleTypeIdentifierSyntax(
16+
attributeName: IdentifierTypeSyntax(
1717
name: .identifier("DictionaryStorage")
1818
)
1919
)

Sources/MacroToolkit/AttributeListElement.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension Sequence where Element == AttributeListElement {
4242
element = .ifConfigDecl(
4343
conditionalCompilationBlock._syntax.with(\.trailingTrivia, [.spaces(1)]))
4444
}
45-
list = list.appending(element)
45+
list += [element]
4646
}
4747
return list
4848
}

Sources/MacroToolkit/BooleanLiteral.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public struct BooleanLiteral: LiteralProtocol {
1010
}
1111

1212
public var value: Bool {
13-
_syntax.booleanLiteral.tokenKind == .keyword(.true)
13+
_syntax.literal.tokenKind == .keyword(.true)
1414
}
1515
}

Sources/MacroToolkit/ConstrainedSugarType.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import SwiftSyntax
22

33
/// Wraps a constrained sugar type (i.e. `any Protocol` or `some Protocol`).
44
public struct ConstrainedSugarType: TypeProtocol {
5-
public var _baseSyntax: ConstrainedSugarTypeSyntax
5+
public var _baseSyntax: SomeOrAnyTypeSyntax
66
public var _attributedSyntax: AttributedTypeSyntax?
77

88
public init(
9-
_ syntax: ConstrainedSugarTypeSyntax,
9+
_ syntax: SomeOrAnyTypeSyntax,
1010
attributedSyntax: AttributedTypeSyntax? = nil
1111
) {
1212
_baseSyntax = syntax

Sources/MacroToolkit/Enum.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct Enum {
1616
}
1717

1818
public var identifier: String {
19-
_syntax.identifier.withoutTrivia().text
19+
_syntax.name.withoutTrivia().text
2020
}
2121

2222
public var cases: [EnumCase] {

Sources/MacroToolkit/EnumCase.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ public struct EnumCase {
1010

1111
/// The case's name
1212
public var identifier: String {
13-
_syntax.identifier.withoutTrivia().description
13+
_syntax.name.withoutTrivia().description
1414
}
1515

1616
/// The value associated with the enum case (either associated or raw).
1717
public var value: EnumCaseValue? {
1818
if let rawValue = _syntax.rawValue {
1919
return .rawValue(rawValue)
20-
} else if let associatedValue = _syntax.associatedValue {
21-
let parameters = Array(associatedValue.parameterList)
20+
} else if let associatedValue = _syntax.parameterClause {
21+
let parameters = Array(associatedValue.parameters)
2222
.map(EnumCaseAssociatedValueParameter.init)
2323
return .associatedValue(parameters)
2424
} else {
@@ -27,6 +27,6 @@ public struct EnumCase {
2727
}
2828

2929
public func withoutValue() -> Self {
30-
EnumCase(_syntax.with(\.rawValue, nil).with(\.associatedValue, nil))
30+
EnumCase(_syntax.with(\.rawValue, nil).with(\.parameterClause, nil))
3131
}
3232
}

Sources/MacroToolkit/FloatLiteral.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public struct FloatLiteral: LiteralProtocol {
1717
public init?(_ syntax: any ExprSyntaxProtocol) {
1818
guard
1919
let operatorSyntax = syntax.as(PrefixOperatorExprSyntax.self),
20-
operatorSyntax.operatorToken?.tokenKind == .prefixOperator("-"),
21-
let literalSyntax = operatorSyntax.postfixExpression.as(FloatLiteralExprSyntax.self)
20+
operatorSyntax.operator.tokenKind == .prefixOperator("-"),
21+
let literalSyntax = operatorSyntax.expression.as(FloatLiteralExprSyntax.self)
2222
else {
2323
// Just treat it as a regular integer literal
2424
guard let literal = syntax.as(FloatLiteralExprSyntax.self).map(Self.init) else {
@@ -32,7 +32,7 @@ public struct FloatLiteral: LiteralProtocol {
3232
}
3333

3434
public var value: Double {
35-
let string = _syntax.floatingDigits.text
35+
let string = _syntax.literal.text
3636

3737
let isHexadecimal: Bool
3838
let stringWithoutPrefix: String

Sources/MacroToolkit/Function.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public struct Function {
1616
}
1717

1818
public var identifier: String {
19-
_syntax.identifier.text
19+
_syntax.name.text
2020
}
2121

2222
public var returnType: Type? {
23-
(_syntax.signature.output?.returnType).map(Type.init)
23+
(_syntax.signature.returnClause?.type).map(Type.init)
2424
}
2525

2626
public var returnsVoid: Bool {
@@ -36,17 +36,17 @@ public struct Function {
3636
}
3737

3838
public var parameters: [FunctionParameter] {
39-
Array(_syntax.signature.input.parameterList).map(FunctionParameter.init)
39+
Array(_syntax.signature.parameterClause.parameters).map(FunctionParameter.init)
4040
}
4141

4242
public var attributes: [AttributeListElement] {
43-
_syntax.attributes.map(Array.init)?.map { attribute in
43+
_syntax.attributes.map { attribute in
4444
switch attribute {
4545
case .attribute(let attributeSyntax):
4646
return .attribute(Attribute(attributeSyntax))
4747
case .ifConfigDecl(let ifConfigDeclSyntax):
4848
return .conditionalCompilationBlock(ConditionalCompilationBlock(ifConfigDeclSyntax))
4949
}
50-
} ?? []
50+
}
5151
}
5252
}

0 commit comments

Comments
 (0)