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

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

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.

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

### 🐛 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.

.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: "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?

) {}
}
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?

/// - 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?

@soumyamahunt
Copy link
Contributor

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

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