Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Package.resolved
*.o
*.d
*.swiftdeps*
*.dia

# CocoaPods
#
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### 🐛 Fixes

* fixed optional types not detected with `valueCoder` strategy ([#141](https://github.com/SwiftyLab/MetaCodable/issues/141)) ([5873c3e](https://github.com/SwiftyLab/MetaCodable/commit/5873c3e33ab98e61c06304bfc2a2c93ab199d65d))
* removed unreachable `default` case warnings for `Bool` type switches in macro-generated code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this, changelog is automatically generated. You can remove this.


## [1.5.0](https://github.com/SwiftyLab/MetaCodable/compare/v1.4.0...v1.5.0) (2025-07-08)

Expand Down
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let package = Package(
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacroExpansion", package: "swift-syntax"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this change?

.product(name: "OrderedCollections", package: "swift-collections"),
]
),
Expand Down
1 change: 1 addition & 0 deletions Package@swift-5.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let package = Package(
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacroExpansion", package: "swift-syntax"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this change?

.product(name: "OrderedCollections", package: "swift-collections"),
]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ extension TaggedEnumSwitcherVariable {
/// - location: The decoding location.
/// - coder: The decoder for cases.
/// - context: The context in which to perform the macro expansion.
/// - default: Whether default case is needed.
/// - default: Whether default case is needed. Note that for Bool type,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to see this warning fixed as well, but your changes seem to be breaking following code expansion for example:

@Codable
@CodedAt("type")
enum Command {
    @CodedAs("load", 12, true)
    case load(key: String)
    @CodedAs("store", 30)
    case store(key: String, value: Int)
}

Can you make the changes to fix above scenario?

/// the default case is automatically skipped since both true and false
/// cases are explicitly handled, avoiding unreachable default warnings.
/// - forceDecodingReturn: Whether to force explicit `return` statements in each
/// switch case. When `true`, adds a `return` statement after the case assignment
/// for early exit. Defaults to `false` for backward compatibility.
Expand Down Expand Up @@ -60,7 +62,7 @@ extension TaggedEnumSwitcherVariable {
}
}

if `default` {
if `default` && header.type != .bool {
SwitchCaseSyntax(label: .default(.init())) {
"break"
}
Expand Down
22 changes: 13 additions & 9 deletions Sources/PluginCore/Variables/Type/EnumVariable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +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, leftParen: nil, rightParen: nil
) {}
}
return ExprSyntax(fExpr)
if args.isEmpty {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this change? May be you can add some test cases that demonstrates what this fixes?

/// 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,
Expand Down
2 changes: 0 additions & 2 deletions Tests/MetaCodableTests/CodedAs/CodedAsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ struct CodedAsTests {
value = try container.decode(Int.self, forKey: CodingKeys.value)
self = .store(key: key, value: value)
return
default:
break
}
}
let typeInt: Int?
Expand Down
1 change: 1 addition & 0 deletions Tests/MetaCodableTests/ConformCodableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,4 @@ struct ConformDecodableTests {
}
}
}