diff --git a/Package.swift b/Package.swift index b7352bd3c..76c25ad60 100644 --- a/Package.swift +++ b/Package.swift @@ -20,7 +20,7 @@ let package = Package( .plugin(name: "MetaProtocolCodable", targets: ["MetaProtocolCodable"]), ], dependencies: [ - .package(url: "https://github.com/swiftlang/swift-syntax.git", "509.1.0"..<"602.0.0"), + .package(url: "https://github.com/swiftlang/swift-syntax.git", "509.1.0"..<"603.0.0"), .package(url: "https://github.com/apple/swift-collections.git", from: "1.0.4"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2"), .package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"), diff --git a/Sources/HelperCoders/ValueCoders/Number.swift b/Sources/HelperCoders/ValueCoders/Number.swift index 24a01c75e..60bcc5df0 100644 --- a/Sources/HelperCoders/ValueCoders/Number.swift +++ b/Sources/HelperCoders/ValueCoders/Number.swift @@ -3,7 +3,7 @@ protocol NumberCodingStrategy: ValueCodingStrategy where Value == Self {} public extension ValueCodingStrategy -where Value: Decodable & ExpressibleByIntegerLiteral & LosslessStringConvertible +where Value: Decodable & ExpressibleByIntegerLiteral & LosslessStringConvertible & Sendable { /// Decodes numeric data from the given `decoder`. /// diff --git a/Sources/PluginCore/Variables/Type/EnumVariable.swift b/Sources/PluginCore/Variables/Type/EnumVariable.swift index 3c621b995..3914db302 100644 --- a/Sources/PluginCore/Variables/Type/EnumVariable.swift +++ b/Sources/PluginCore/Variables/Type/EnumVariable.swift @@ -84,13 +84,19 @@ package struct EnumVariable: TypeVariable, DeclaredVariable { let caseEncodeExpr: CaseCode = { name, variables in let args = Self.encodingArgs(representing: variables) let callee: ExprSyntax = ".\(name)" - let fExpr = - if !args.isEmpty { - FunctionCallExprSyntax(callee: callee) { args } - } else { - FunctionCallExprSyntax(calledExpression: callee) {} - } - return ExprSyntax(fExpr) + if args.isEmpty { + /// No associated values: return just the case name without parentheses + return callee + } else { + let fExpr = FunctionCallExprSyntax( + calledExpression: callee, + leftParen: .leftParenToken(), + arguments: args, + rightParen: .rightParenToken(), + trailingClosure: nil + ) + return ExprSyntax(fExpr) + } } self.init( from: decl, in: context, @@ -878,3 +884,4 @@ fileprivate extension EnumVariable { /// This encoder is passed to each case for encoding. static var contentEncoder: TokenSyntax { "contentEncoder" } } + diff --git a/Tests/MetaCodableTests/ConformCodableTests.swift b/Tests/MetaCodableTests/ConformCodableTests.swift index 6a8a793ce..3f294cd03 100644 --- a/Tests/MetaCodableTests/ConformCodableTests.swift +++ b/Tests/MetaCodableTests/ConformCodableTests.swift @@ -38,6 +38,15 @@ struct ConformEncodableTests { .init(message: "Remove @ConformEncodable attribute") ] ), + .init( + id: Codable.misuseID, + message: + "@Codable can't be used in combination with @ConformEncodable", + line: 2, column: 1, + fixIts: [ + .init(message: "Remove @Codable attribute") + ] + ), .init( id: ConformEncodable.misuseID, message: @@ -491,3 +500,4 @@ struct ConformDecodableTests { } } } +