Skip to content

Conversation

@qizh
Copy link

@qizh qizh commented Nov 27, 2025

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 releases

  • Added¹ SwiftSyntaxMacroExpansion: Explicit dependency added to PluginCore to resolve Xcode's dependency scanner warnings

    📙¹ Dependency Addition Explanation & Reasoning

    SwiftSyntaxMacroExpansion Dependency Addition

    Problem Statement

    Xcode's dependency scanner was generating warnings about implicit dependencies on the SwiftSyntaxMacroExpansion module. While the package compiled successfully, the implicit dependency meant that Xcode couldn't properly track the module dependency graph.

    Root Cause

    The MetaCodable package uses MacroExpansionContext and BasicMacroExpansionContext types from the SwiftSyntaxMacroExpansion module 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

    .product(name: "SwiftSyntaxMacroExpansion", package: "swift-syntax")

    Should be added to the dependencies array for three targets:

    1. ❇️ PluginCore (Package.swift:38, Package@swift-5.swift:37)
    2. ☑️ MacroPlugin (already existed: Package.swift#L50)
    3. ☑️ 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

    2. Protocol Code Generation in ProtocolGen

    3. Testing Infrastructure

    Impact

    • ✅ Resolves Xcode dependency scanner warnings
    • ✅ Makes dependency graph explicit and traceable
    • ✅ No functional changes to the codebase
    • ✅ Maintains compatibility with both Swift 5.9 and Swift 6.0 manifests
    • ✅ Aligns with Swift Package Manager best practices for explicit dependency declaration

Code Improvements

  • Enum encoding logic: Refactored enum case encoding in EnumVariable so cases without associated values are encoded as just the case name (without parentheses), improving generated code correctness
  • Bool switch warnings: Skip generating default case for Bool type switches since both true and false cases are explicitly handled, eliminating "default will never be executed" warnings

Protocol Enhancements

  • Sendable constraint: Added Sendable constraint to generic requirements for numeric value coding strategies, improving safety for concurrent use

Maintenance, Docs, Build Stability, Verification, and Backward-Compatible Refinements

Testing and Diagnostics

  • Attribute misuse test: Added new test case to ConformEncodableTests to check for misuse when @Codable is used with @ConformEncodable, providing better diagnostics for attribute conflicts
  • Test cleanup: Removed duplicate diagnostic expectations from ConformCodableTests.swift that were incorrectly preserved during merge conflict resolution

Documentation Updates

  • Inline documentation: Updated decodeSwitchExpression documentation to explain Bool type handling behavior
  • CHANGELOG: Added entry documenting the Bool switch warning fix

Build Configuration

  • Git ignore: Added *.dia files to .gitignore (Swift dependency analysis files, similar to .d and .o files)
  • Package configuration: Updated both Package.swift and Package@swift-5.swift to maintain Swift 5/6 compatibility

Verification

  • All tests pass without warnings
  • No warnings in command line build (swift build)
  • No warnings in Xcode build (MetaCodable-Package scheme)
  • Both Swift 5 and Swift 6 compatibility maintained

Context

The compiler warning fixes address issues that were particularly noticeable when:

  • Using @CodedAs with Bool raw values in enums
  • Building in Xcode with aggressive dependency scanning enabled

All changes maintain backward compatibility while providing cleaner build output for developers using MetaCodable.


Additional Changes (Jan 30, 2026)

🐛 Bug Fix Refinement

  • Fixed partial Bool coverage in TaggedEnumSwitcherVariable
    • The original Bool switch fix incorrectly skipped the default case for ALL Bool switches
    • Now correctly checks if both true and false values are present before skipping default case
    • Fixes unreachable code warnings when only one Bool value is specified (e.g., @CodedAs<Bool>("isActive", ifTrue: SomeType.self))

🧪 Test Organization & Coverage

Coverage Improvements

  • Added tests for previously uncovered code paths:
    • HelperCoder: decodeIfPresent, encode, encodeIfPresent
    • ConditionalCoder: decodeIfPresent, encodeIfPresent
    • DefaultSequenceElementCoding: optional encoding/decoding methods
    • DynamicCodableIdentifier: CodingKey conformance methods
  • Added partial Bool coverage tests in CodedAsMixedTypesTests.swift

Test Suite Organization

  • Added @Suite declarations to all 50 test files for logical grouping
  • Replaced 565 unnamed @Test() with descriptive @Test("meaningful name")
  • Created Tags.swift with 30+ tag definitions for test filtering:
    • Macro tags: .codable, .codedAt, .codedIn, .codedBy, etc.
    • Test type tags: .macroExpansion, .encoding, .decoding, .errorHandling
    • Feature tags: .helperCoders, .dynamicCoding, .generics
  • Reorganized tests into nested suites where appropriate
  • Added Tests/TODO/CoverageTracking.md for tracking coverage progress

🔧 CI/CD

  • Added .github/workflows/swift.yml for build and test automation
    • Uses default Xcode toolchain on macos-latest
    • Includes SwiftPM dependency caching
    • Runs swift build and swift test --parallel --verbose

📝 Other

  • Added .markdownlint.json configuration

qizh added 2 commits November 27, 2025 21:34
- [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.
@qizh qizh marked this pull request as ready for review November 27, 2025 14:42
Copilot AI review requested due to automatic review settings November 27, 2025 14:42
Copy link

Copilot AI left a 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-syntax version range from "509.1.0"..<"602.0.0" to "509.1.0"..<"603.0.0"
  • Refactored FunctionCallExprSyntax initialization to use calledExpression: parameter instead of deprecated callee:
  • Added SendableMetatype constraint to ValueCodingStrategy extension 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

@qizh qizh marked this pull request as draft November 27, 2025 14:47
qizh added 3 commits November 27, 2025 22:30
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`.
@qizh qizh marked this pull request as ready for review November 27, 2025 16:03
@qizh qizh requested a review from Copilot November 27, 2025 16:05
Copy link

Copilot AI left a 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.

@paulgessinger
Copy link

paulgessinger commented Dec 21, 2025

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?

@qizh
Copy link
Author

qizh commented Dec 22, 2025

This PR looks AI-generated.

Partially, it is.

I've made this update for myself, and I'm using my fork in production.
PR was made just in case someone will find it useful as well.

@paulgessinger
Copy link

@qizh It's been useful for me, so thanks for sharing!

@soumyamahunt
Copy link
Contributor

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?

qizh added 6 commits January 21, 2026 18:24
#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`
@qizh
Copy link
Author

qizh commented Jan 21, 2026

@qizh can you rebase your PR?

@soumyamahunt done

@soumyamahunt
Copy link
Contributor

Thanks for updating this @qizh, please have a look on the comments when you can.

qizh added 15 commits January 30, 2026 15:05
…iles

Updated 50 test files to:
- Add @suite declarations for logical grouping of tests
- Replace unnamed @test() with @test("descriptive name")
- Group related tests into nested suites where appropriate
- Improve test organization and readability

All tests continue to pass after the updates.
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
@qizh qizh requested a review from soumyamahunt January 30, 2026 10:24
qizh added 3 commits January 30, 2026 17:37
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`.
@qizh qizh changed the title Update swift-syntax version and improve type constraints to resolve errors & warnings Update swift-syntax, fix Bool switch warnings, and improve test organization & coverage Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants