diff --git a/.spi.yml b/.spi.yml index ff36ee998..4949a4c2c 100644 --- a/.spi.yml +++ b/.spi.yml @@ -1,4 +1,4 @@ version: 1 builder: configs: - - documentation_targets: [CodableMacroPlugin, MetaCodable] \ No newline at end of file + - documentation_targets: [MetaCodable, HelperCoders] \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 844b16b8b..ff96b7538 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,4 +10,8 @@ "editor.unicodeHighlight.allowedCharacters": { "-": true }, + "swift.disableAutoResolve": true, + "swift.swiftEnvironmentVariables": { + "SWIFT_SYNTAX_EXTENSION_MACRO_FIXED": "true" + }, } \ No newline at end of file diff --git a/Package.swift b/Package.swift index 455e41177..0dd554836 100644 --- a/Package.swift +++ b/Package.swift @@ -45,3 +45,19 @@ let package = Package( ), ] ) + +if Context.environment["SWIFT_SYNTAX_EXTENSION_MACRO_FIXED"] != nil { + package.dependencies.remove(at: 0) + package.dependencies.append( + .package( + url: "https://github.com/soumyamahunt/swift-syntax.git", + branch: "extension-macro-assert-fix" + ) + ) + + package.targets.forEach { target in + var settings = target.swiftSettings ?? [] + settings.append(.define("SWIFT_SYNTAX_EXTENSION_MACRO_FIXED")) + target.swiftSettings = settings + } +} diff --git a/Tests/MetaCodableTests/CodableTests.swift b/Tests/MetaCodableTests/CodableTests.swift index 3dce6e70a..0c158df30 100644 --- a/Tests/MetaCodableTests/CodableTests.swift +++ b/Tests/MetaCodableTests/CodableTests.swift @@ -104,7 +104,8 @@ final class CodableTests: XCTestCase { case value = "value" } } - """ + """, + conformsTo: ["Codable": ["Decodable"]] ) } @@ -142,7 +143,8 @@ final class CodableTests: XCTestCase { case value = "value" } } - """ + """, + conformsTo: ["Codable": ["Encodable"]] ) } @@ -173,7 +175,8 @@ final class CodableTests: XCTestCase { func encode(to encoder: Encoder) throws { } } - """ + """, + conformsTo: ["Codable": []] ) } } @@ -182,6 +185,9 @@ func assertMacroExpansion( _ originalSource: String, expandedSource: String, diagnostics: [DiagnosticSpec] = [], + conformsTo conformanceMap: [String: [TypeSyntax]] = [ + "Codable": ["Decodable", "Encodable"] + ], testModuleName: String = "TestModule", testFileName: String = "test.swift", indentationWidth: Trivia = .spaces(4), @@ -204,6 +210,7 @@ func assertMacroExpansion( "CodingKeys": CodingKeys.self, "IgnoreCodingInitialized": IgnoreCodingInitialized.self, ], + conformsTo: conformanceMap, testModuleName: testModuleName, testFileName: testFileName, indentationWidth: indentationWidth, file: file, line: line @@ -221,14 +228,9 @@ extension DiagnosticSpec { return .init( id: MessageID( domain: "SwiftSyntaxMacroExpansion", - id: "accessorMacroOnVariableWithMultipleBindings" + id: "peerMacroOnVariableWithMultipleBindings" ), - message: - "swift-syntax applies macros syntactically and" - + " there is no way to represent a variable declaration" - + " with multiple bindings that have accessors syntactically." - + " While the compiler allows this expansion," - + " swift-syntax cannot represent it and thus disallows it.", + message: "peer macro can only be applied to a single variable", line: line, column: column ) } diff --git a/Tests/MetaCodableTests/CodedAtTests.swift b/Tests/MetaCodableTests/CodedAtTests.swift index 9c6941d74..8ab037bd7 100644 --- a/Tests/MetaCodableTests/CodedAtTests.swift +++ b/Tests/MetaCodableTests/CodedAtTests.swift @@ -51,16 +51,7 @@ final class CodedAtTests: XCTestCase { } """, diagnostics: [ - .multiBinding(line: 2, column: 5), - .init( - id: CodedAt.misuseID, - message: - "@CodedAt can't be used with grouped variables declaration", - line: 2, column: 5, - fixIts: [ - .init(message: "Remove @CodedAt attribute") - ] - ), + .multiBinding(line: 2, column: 5) ] ) } diff --git a/Tests/MetaCodableTests/GroupedMutableVariableTests.swift b/Tests/MetaCodableTests/GroupedMutableVariableTests.swift index 4c2d28a10..45a0ec37c 100644 --- a/Tests/MetaCodableTests/GroupedMutableVariableTests.swift +++ b/Tests/MetaCodableTests/GroupedMutableVariableTests.swift @@ -50,8 +50,7 @@ final class GroupedMutableVariableTests: XCTestCase { case three = "three" } } - """, - diagnostics: [.multiBinding(line: 4, column: 5)] + """ ) } @@ -106,8 +105,7 @@ final class GroupedMutableVariableTests: XCTestCase { case three = "three" } } - """, - diagnostics: [.multiBinding(line: 4, column: 5)] + """ ) } @@ -199,8 +197,7 @@ final class GroupedMutableVariableTests: XCTestCase { case three = "three" } } - """, - diagnostics: [.multiBinding(line: 4, column: 5)] + """ ) } @@ -255,8 +252,7 @@ final class GroupedMutableVariableTests: XCTestCase { case three = "three" } } - """, - diagnostics: [.multiBinding(line: 4, column: 5)] + """ ) } @@ -311,8 +307,7 @@ final class GroupedMutableVariableTests: XCTestCase { case three = "three" } } - """, - diagnostics: [.multiBinding(line: 4, column: 5)] + """ ) } } diff --git a/Tests/MetaCodableTests/GroupedVariableTests.swift b/Tests/MetaCodableTests/GroupedVariableTests.swift index 3baf84eee..83aba681e 100644 --- a/Tests/MetaCodableTests/GroupedVariableTests.swift +++ b/Tests/MetaCodableTests/GroupedVariableTests.swift @@ -50,8 +50,7 @@ final class GroupedVariableTests: XCTestCase { case three = "three" } } - """, - diagnostics: [.multiBinding(line: 4, column: 5)] + """ ) } @@ -97,8 +96,7 @@ final class GroupedVariableTests: XCTestCase { case two = "two" } } - """, - diagnostics: [.multiBinding(line: 4, column: 5)] + """ ) } @@ -186,8 +184,7 @@ final class GroupedVariableTests: XCTestCase { case three = "three" } } - """, - diagnostics: [.multiBinding(line: 4, column: 5)] + """ ) } @@ -233,8 +230,7 @@ final class GroupedVariableTests: XCTestCase { case three = "three" } } - """, - diagnostics: [.multiBinding(line: 4, column: 5)] + """ ) } @@ -280,8 +276,7 @@ final class GroupedVariableTests: XCTestCase { case three = "three" } } - """, - diagnostics: [.multiBinding(line: 4, column: 5)] + """ ) } } diff --git a/package.json b/package.json index 6abb89e1d..97147086e 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "scripts": { "build": "npm exec --package=swiftylab-ci -- build.js", - "test": "npm exec --package=swiftylab-ci -- test.js", + "test": "SWIFT_SYNTAX_EXTENSION_MACRO_FIXED=true npm exec --package=swiftylab-ci -- test.js", "archive": "echo implement", "generate": "echo implement", "format": "npm exec --package=swiftylab-ci -- format.js",