-
-
Notifications
You must be signed in to change notification settings - Fork 42
Update swift-syntax, fix Bool switch warnings, and improve test organization & coverage
#150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- [x] Bumped `swift-syntax` dependency to allow up to `603.0.0`. - [x] Added `SendableMetatype` constraint to `NumberCodingStrategy` extension. - [x] Refactored `caseEncodeExpr` in `EnumVariable` for consistent `FunctionCallExprSyntax` usage.
- [x] Corrected indentation for the `caseEncodeExpr` closure to maintain consistent formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR updates the swift-syntax dependency to support versions up to 603.0.0 and addresses breaking API changes introduced in newer versions of the library.
- Updated
swift-syntaxversion range from"509.1.0"..<"602.0.0"to"509.1.0"..<"603.0.0" - Refactored
FunctionCallExprSyntaxinitialization to usecalledExpression:parameter instead of deprecatedcallee: - Added
SendableMetatypeconstraint toValueCodingStrategyextension for number types
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Package.swift | Bumped swift-syntax dependency upper bound to 603.0.0 |
| Sources/PluginCore/Variables/Type/EnumVariable.swift | Updated FunctionCallExprSyntax API usage from callee: to calledExpression: for consistency |
| Sources/HelperCoders/ValueCoders/Number.swift | Added SendableMetatype constraint to ValueCodingStrategy extension |
Replaces the `SendableMetatype` constraint with `Sendable` in the `ValueCodingStrategy` extension to align with updated protocol requirements or type definitions.
- [x] Refactors `caseEncodeExpr` to return only the case name for enum cases without associated values, avoiding unnecessary parentheses. This improves code generation for enums with simple cases.
- [x] Update `ConformEncodableTests.misuseWithCodable` to expect four diagnostics. - [x] Ensure diagnostic IDs, messages, fix-its, and line/column positions match emitted results: - [x] Two diagnostics for `@ConformEncodable` at line 1, column 1. - [x] Two diagnostics for `@Codable` at line 2, column 1. - [x] Mirrors the pattern already used in `misuseWithDecodable`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
|
I'm very interested in this, because it currently keeps me on swift-syntax 601, which seems to cause issues with the (I think) newly bundled versions of this package with XCode. This PR looks AI generated, but is there anything preventing this from proceeding? |
Partially, it is. I've made this update for myself, and I'm using my fork in production. |
|
@qizh It's been useful for me, so thanks for sharing! |
|
Sorry for not responding to this earlier. Since the swift-syntax prebuilt bug: swiftlang/swift-package-manager#9240, this repo and the CI/CD for this was failing. I paused any kind of contribution till this is fixed. This seems to be fixed now. @qizh can you rebase your PR? |
#Conflicts: # Sources/PluginCore/Variables/Type/EnumVariable.swift # Tests/MetaCodableTests/ConformCodableTests.swift
Skip generating default case in switch statements when the header type is Bool, since both true and false cases are already explicitly handled. This eliminates "default will never be executed" compiler warnings in macro-generated code. - Update decodeSwitchExpression to check for Bool type before adding default - Update test expectation to match new behavior - Add inline documentation explaining the Bool type handling
Add explicit SwiftSyntaxMacroExpansion dependency to PluginCore target to resolve Xcode's dependency scanner warnings. The scanner detects that MacroExpansionContext (used extensively in PluginCore) requires this module as a transitive dependency. Applies to both Package.swift and Package@swift-5.swift for Swift 5/6 compatibility.
Add Swift dependency analysis files (*.dia) to gitignore as they are temporary build artifacts similar to .d and .o files.
Remove duplicate diagnostic test expectations that were incorrectly preserved during merge conflict resolution.
- [x] fix: resolve compiler warnings - [x] merge: from `upstream/main`
@soumyamahunt done |
Sources/PluginCore/Variables/Enum/Switcher/TaggedEnumSwitcherVariable.swift
Outdated
Show resolved
Hide resolved
|
Thanks for updating this @qizh, please have a look on the comments when you can. |
Updated all 565 tests across 50 files: - Analyzed actual test logic to generate descriptive names - Ensured all test names are unique across the entire test suite - Applied proper capitalization and English grammar - Preserved parameterized tests with arguments: - Replaced generic names like "expansion" with context-specific descriptions e.g., "Generates @codable conformance for struct with 'open' access" - Error tests now clearly state what error they verify e.g., "Reports error when @codingkeys is used without @codable" Test names now immediately communicate what each test verifies, making test failures instantly understandable without needing to inspect the test code. Updated Tests/TODO/CoverageTracking.md to document the test organization improvements.
Added Swift Testing tags to organize and filter the 529 tests: - Created Tags.swift with 30+ tag definitions covering: • Macro tags (@codable, @codedat, @codedin, etc.) • Test type tags (macroExpansion, encoding, decoding, errorHandling) • Feature tags (helperCoders, dynamicCoding, generics, etc.) • Type tags (structs, classes, enums, rawRepresentable) • Helper coder specific tags • Coverage tag for coverage-improvement tests - Tagged all 529 tests based on actual content analysis - Tags enable filtering tests by macro, feature, or test type - Example: @test("...", .tags(.codable, .macroExpansion, .structs)) Updated Tests/TODO/CoverageTracking.md with tagging documentation and usage examples. All 565 tests continue to pass with tags applied.
Added multiline formatting for @test declarations with many tags: - Tests with many tags (>3) now use multiline format - Each tag on its own line for better readability - Applied to CodableTests and GenericsTests as examples - Format: @test( "Test name", .tags( .tag1, .tag2, .tag3 ) ) All 565 tests continue to pass.
- Add tests for partial Bool coverage in CodedAsMixedTypesTests.swift - Fix decodeSwitchExpression to only skip default case when both true and false Bool values are covered - Previously, default case was skipped for ALL Bool switches, causing unreachable code warnings when only one Bool value was specified The fix checks if both true and false are present in the enum cases before deciding to skip the default case in Bool switches.
- Add tests for partial Bool coverage in CodedAsMixedTypesTests.swift - Fix decodeSwitchExpression to only skip default case when both true and false Bool values are covered - Previously, default case was skipped for ALL Bool switches, causing unreachable code warnings when only one Bool value was specified The fix checks if both true and false are present in the enum cases before deciding to skip the default case in Bool switches. (cherry picked from commit bb8f9a5)
Remove leftover merge conflict markers (`<<<<<<< HEAD, =======, >>>>>>>`) from the test file that were accidentally committed during the previous merge.
This workflow will be disabled on GitHub.
With another badge @qizh is interested in
Swift 6.2.1 has a bug causing fatalError during ExpandSynthesizedMemberMacroRequest when processing @codable macro on protocols (ExtPost in PostPage.swift)
Swift 6.1/6.2 from swift-actions has compiler crash during macro expansion. Default Xcode toolchain on macos-latest should be more stable.
Improve test coverage and organization
…ptions - [x] Reorganize `ConditionalCoderTests`, `DefaultSequenceElementCodingTests`, and `DynamicCodableIdentifierTests` into nested test suites. - [x] Update test descriptions to be more concise and descriptive. - [x] Remove `CHANGELOG` entry about unreachable default case warnings (again 🤦🏻♂️). - [x] Simplify multi-line test attribute formatting in `CodableTests`.
swift-syntax version and improve type constraints to resolve errors & warningsswift-syntax, fix Bool switch warnings, and improve test organization & coverage
This pull request updates dependencies, improves enum case encoding logic, enhances protocol constraints for numeric value coders, adds a new test for attribute misuse, and fixes compiler warnings. The changes focus on compatibility, correctness, improved diagnostics, and cleaner build output.
Dependency Updates
Updated swift-syntax dependency: Increased the upper bound to allow versions up to
603.0.0, ensuring compatibility with newer releasesAdded¹
SwiftSyntaxMacroExpansion: Explicit dependency added to PluginCore to resolve Xcode's dependency scanner warnings📙¹ Dependency Addition Explanation & Reasoning
SwiftSyntaxMacroExpansionDependency AdditionProblem Statement
Xcode's dependency scanner was generating warnings about implicit dependencies on the
SwiftSyntaxMacroExpansionmodule. While the package compiled successfully, the implicit dependency meant that Xcode couldn't properly track the module dependency graph.Root Cause
The
MetaCodablepackage usesMacroExpansionContextandBasicMacroExpansionContexttypes from theSwiftSyntaxMacroExpansionmodule throughout the codebase, but this dependency was only declared implicitly through other swift-syntax modules. The Swift Package Manager resolved it transitively, but Xcode's dependency scanner requires explicit declarations for all directly-imported modules.Solution
Should be added to the dependencies array for three targets:
PluginCore(Package.swift:38, Package@swift-5.swift:37)MacroPlugin(already existed: Package.swift#L50)ProtocolGen(already existed: Package.swift#L64)This makes the implicit dependency explicit, satisfying both the Swift Package Manager and Xcode's dependency scanner.
Usage Across the Codebase
1. Macro Expansion in PluginCore
Codable+Expansion.swift:MacroExpansionContextparameter in the main expansion methodDecodable+Expansion.swift: Context passed to create type variable representationsEnumVariable.swift: Context stored for later code generation phasesCodingKeysMap.swift: Context used to generateCodingKeysenum declarations2. Protocol Code Generation in
ProtocolGenGenerate.swift: Direct import and usage ofBasicMacroExpansionContext3. Testing Infrastructure
CodableTests.swiftandConformCodableTests.swift: Import module for macro expansion testingassertMacroExpansion()test helper functionsImpact
5.9and Swift6.0manifestsCode Improvements
EnumVariableso cases without associated values are encoded as just the case name (without parentheses), improving generated code correctnesstrueandfalsecases are explicitly handled, eliminating "default will never be executed" warningsProtocol Enhancements
Sendableconstraint to generic requirements for numeric value coding strategies, improving safety for concurrent useMaintenance, Docs, Build Stability, Verification, and Backward-Compatible Refinements
Testing and Diagnostics
ConformEncodableTeststo check for misuse when@Codableis used with@ConformEncodable, providing better diagnostics for attribute conflictsConformCodableTests.swiftthat were incorrectly preserved during merge conflict resolutionDocumentation Updates
decodeSwitchExpressiondocumentation to explain Bool type handling behaviorBuild Configuration
*.diafiles to.gitignore(Swift dependency analysis files, similar to.dand.ofiles)Package.swiftandPackage@swift-5.swiftto maintain Swift 5/6 compatibilityVerification
swift build)MetaCodable-Packagescheme)Context
The compiler warning fixes address issues that were particularly noticeable when:
@CodedAswithBoolraw values in enumsAll changes maintain backward compatibility while providing cleaner build output for developers using MetaCodable.
Additional Changes (Jan 30, 2026)
🐛 Bug Fix Refinement
TaggedEnumSwitcherVariabletrueandfalsevalues are present before skipping default case@CodedAs<Bool>("isActive", ifTrue: SomeType.self))🧪 Test Organization & Coverage
Coverage Improvements
HelperCoder:decodeIfPresent,encode,encodeIfPresentConditionalCoder:decodeIfPresent,encodeIfPresentDefaultSequenceElementCoding: optional encoding/decoding methodsDynamicCodableIdentifier:CodingKeyconformance methodsCodedAsMixedTypesTests.swiftTest Suite Organization
@Suitedeclarations to all 50 test files for logical grouping@Test()with descriptive@Test("meaningful name")Tags.swiftwith 30+ tag definitions for test filtering:.codable,.codedAt,.codedIn,.codedBy, etc..macroExpansion,.encoding,.decoding,.errorHandling.helperCoders,.dynamicCoding,.genericsTests/TODO/CoverageTracking.mdfor tracking coverage progress🔧 CI/CD
.github/workflows/swift.ymlfor build and test automationmacos-latestswift buildandswift test --parallel --verbose📝 Other
.markdownlint.jsonconfiguration