-
-
Notifications
You must be signed in to change notification settings - Fork 42
Update swift-syntax version and improve type constraints to resolve errors & warnings
#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 |
| ### 🐛 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 |
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.
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"), |
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.
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"), |
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.
Any reason for this change?
| ) {} | ||
| } | ||
| return ExprSyntax(fExpr) | ||
| if args.isEmpty { |
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.
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, |
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.
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?
|
Thanks for updating this @qizh, please have a look on the comments when you can. |
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
603.0.0, ensuring compatibility with newer releasesCode 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 useTesting 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.