Skip to content

Support for Swift 6.1's stricter type syntax #48

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

Merged
merged 6 commits into from
Mar 5, 2025

Conversation

gohanlon
Copy link
Owner

@gohanlon gohanlon commented Mar 5, 2025

Fix @Init(type:) and @InitWrapper(type:) on Swift 6.1, and some housekeeping.

This primarily addresses an incompatibility with Swift 6.1 (included in Xcode 16.3 beta) where the macro would fail when used with type parameters. In Swift 6.1, metatype syntax requires the .self suffix when used in this context.

Before this fix:

  • Code like @Init(type: String?) would fail with type errors in Swift 6.1
  • This was a previously warned deprecation that is now enforced in Swift 6.1

The implementation now:

  • Correctly handles both Swift 5 style type references (without .self)
  • Supports Swift 6.1 style type references (with .self suffix)
  • Maintains backward compatibility while being future-proof

Additional housekeeping improvements:

  • Updated copyright years
  • Removed unused functions
  • Improved clean target with better error handling
  • Updated swift-snapshot-testing dependency
  • Added Swift 6.0.2 Linux testing to CI

Fixes #47

Note the exact Swift version I tested against:

% /Applications/Xcode-16.3.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift --version
swift-driver version: 1.120.2 Apple Swift version 6.1 (swiftlang-6.1.0.106.4 clang-1700.0.9.2)
Target: arm64-apple-macosx15.0

gohanlon added 6 commits March 4, 2025 12:42
The formatting functions were moved to MemberwiseInitFormatter but that
commit missed removing them from MemberwiseInitMacro.
This addresses an incompatibility with Swift 6.1 (included in Xcode 16.3
beta) where the macro would fail when used with type parameters. In
Swift 6.1, metatype syntax requires the .self suffix when used in this
context.

Before this fix:
- Code like `@InitRaw(type: String?)` would fail with type errors in
  Swift 6.1
- This was a previously warned deprecation that is now enforced in Swift
  6.1

The implementation now:
- Correctly handles both Swift 5 style type references (without `.self`)
- Supports Swift 6.1 style type references (with `.self` suffix)
- Maintains backward compatibility while being future-proof

Fixes #47
This works around an (erroneous) compiler build error on
swift-issue-reporting.

See: pointfreeco/swift-issue-reporting#150
@gohanlon gohanlon self-assigned this Mar 5, 2025
@gohanlon gohanlon merged commit 147ce36 into main Mar 5, 2025
4 checks passed
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.

Failed to build with all @Init macro with type: as parameter
1 participant