Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
db33503
Update `swift-syntax` version and improve type constraints
qizh Nov 27, 2025
a9b3f01
Bring indentation back in `EnumVariable.swift`
qizh Nov 27, 2025
551c9a1
Update protocol constraint from `SendableMetatype` to `Sendable`
qizh Nov 27, 2025
af382df
Fix enum case encoding for cases without arguments
qizh Nov 27, 2025
44558a5
Align `misuseWithCodable` diagnostics with actual macro output
qizh Nov 27, 2025
6ca0d90
Merge remote-tracking branch 'refs/remotes/upstream/main'
qizh Jan 21, 2026
67ab745
fix: remove unreachable default case warnings for Bool type switches
qizh Jan 21, 2026
37c080c
fix: add SwiftSyntaxMacroExpansion dependency to PluginCore
qizh Jan 21, 2026
ea720d5
chore: add *.dia to gitignore
qizh Jan 21, 2026
0b3f7dc
fix: remove duplicate diagnostic expectations in ConformCodableTests
qizh Jan 21, 2026
6da09a6
Merge pull request #1 from qizh/fix/warnings-cleanup
qizh Jan 21, 2026
4a3190a
Update `CHANGELOG.md`
qizh Jan 30, 2026
a405f1b
Fix: Handle partial `Bool` coverage in `switch` statements
qizh Jan 30, 2026
342f6ff
test: add coverage tests for HelperCoder and related types
qizh Jan 30, 2026
3873f76
Merge branch 'merge/upstream'
qizh Jan 30, 2026
2d44730
test: add @Suite declarations and meaningful test names to all test f…
qizh Jan 30, 2026
edeba0b
test: improve all test names with meaningful, unique descriptions
qizh Jan 30, 2026
c1dd2be
test: add comprehensive tagging system for all tests
qizh Jan 30, 2026
b031947
style: format long @Test declarations as multiline for readability
qizh Jan 30, 2026
aa9002e
docs: fix markdown lint error - add blank line before code block
qizh Jan 30, 2026
bb8f9a5
fix: handle partial Bool coverage in TaggedEnumSwitcherVariable
qizh Jan 30, 2026
e6e5a12
fix: handle partial Bool coverage in TaggedEnumSwitcherVariable
qizh Jan 30, 2026
161b144
fix: remove merge conflict markers from `CodedAsMixedTypesTests.swift`
qizh Jan 30, 2026
6cb6b70
Merge origin/main into tests/improve/coverage/30-01-26
qizh Jan 30, 2026
2344087
Add Swift CI workflow for build and test automation
qizh Jan 30, 2026
fae5691
Disable main.yml workflow in favor of swift.yml
qizh Jan 30, 2026
1f3e57c
Re-enable `main.yml` workflow by removing the `.disabled` extension.
qizh Jan 30, 2026
4e57d33
chore: simplify Swift workflow name to "Swift `build` & `test`"
qizh Jan 30, 2026
3ffa20e
Update `README.md`
qizh Jan 30, 2026
6ca3eea
Fix: Downgrade to Swift 6.1 to avoid compiler crash in macro expansion
qizh Jan 30, 2026
c589543
Fix: Use default Xcode toolchain instead of swift-actions/setup-swift
qizh Jan 30, 2026
4b6fe3d
Merge pull request #2 from qizh/tests/improve/coverage/30-01-26
qizh Jan 30, 2026
201ce15
Refactor test organization with nested suites and improve test descri…
qizh Jan 30, 2026
868dc07
Update `swift-syntax` dependency upper bound to support version `603.x`
qizh Feb 4, 2026
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

## [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"),
.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"),
.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,
/// 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?

Copy link
Author

@qizh qizh Jan 30, 2026

Choose a reason for hiding this comment

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

@soumyamahunt, I've updated the existing WithAnyCodableLiteralEnum/expansion test at the same time with this fix.
The test should be self-explanatory, though let me know if it's not and a separate test is required.

Copy link
Author

Choose a reason for hiding this comment

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

BTW I'd like to give names to @Suites and @Tests.
@soumyamahunt what do you think about it, would you approve?

Like the following:

@Suite("Logical tests group")
struct SomeTestSuite {
    @Test("Test Bool expansion")
    func textBoolExpansion() async {
        /// ...
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW I'd like to give names to @suites and @tests.
@soumyamahunt what do you think about it, would you approve?

I am okay with having readable test suite and method names.

@soumyamahunt, I've updated the existing WithAnyCodableLiteralEnum/expansion test at the same time with this fix.
The test should be self-explanatory, though let me know if it's not and a separate test is required.

@qizh the tests you have mentioned here is for the changes you have done in Sources/PluginCore/Variables/Enum/Switcher/TaggedEnumSwitcherVariable.swift file. Can you point to the test that is for changes to this file? If this change doesn't address anything please revert this change.

Copy link
Author

Choose a reason for hiding this comment

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

@soumyamahunt Good catch — I clearly need more coffee when referencing tests. ☕

The test you're looking for is CodedAsMixedTypesTests.swift (added in commit a405f1b), specifically:

Previously existing indirect tests:

  • Tests/MetaCodableTests/CodedAt/CodedAtEnumTests.swift - tests tagged enums with @CodedAt
  • Tests/MetaCodableTests/CodedAs/CodedAsTests.swift:275-450 - tests @CodedAs with mixed literal types (Bool, Int, String, Double) where both true and false are covered

What the fix addresses:
The previous code skipped the default case for all Bool switches (header.type != .bool), which worked fine when both true and false were covered. But when @CodedAs specifies only one Bool value (e.g., @CodedAs("load", 12, true) on one case, nothing on the other), the generated switch would be missing a default case — causing Swift to complain about non-exhaustive switch.

The fix checks if both true AND false are present before skipping the default case. The tests verify exactly this scenario with mixed literal types.


Let me know if this clarifies things or if you'd like the tests restructured.

Copy link
Contributor

Choose a reason for hiding this comment

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

@qizh you are still describing the changes for Sources/PluginCore/Variables/Enum/Switcher/TaggedEnumSwitcherVariable.swift. Can you provide me the result of tests without the change in this file? If you revert the changes in this file Sources/PluginCore/Variables/Type/EnumVariable.swift does any tests fail?

/// 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 {
}
}
}