Skip to content

fix: AddComponentModifierMacro error when using SwiftSyntax 5xx#57

Merged
ElonPark merged 3 commits into
mainfrom
bug/elon/fix-swift-syntax-5-error
Sep 18, 2025
Merged

fix: AddComponentModifierMacro error when using SwiftSyntax 5xx#57
ElonPark merged 3 commits into
mainfrom
bug/elon/fix-swift-syntax-5-error

Conversation

@ElonPark

Copy link
Copy Markdown
Member

Background (Required)

  • The lexicalContext API in SwiftSyntax is only available from version 600 onwards
  • The AddComponentModifierMacro was using this API without proper version checks, causing compatibility issues with SwiftSyntax 5xx versions
  • This change ensures proper version compatibility by conditionally compiling the macro implementation

Changes (Required)

  • AddComponentModifierMacro.swift:
    • Added conditional compilation using #if canImport(SwiftSyntax600) to wrap the implementation that uses lexicalContext
    • Returns an error message for SwiftSyntax versions below 600: "@AddComponentModifier macro requires SwiftSyntax 600.0.0 or later."
    • Removed duplicate code blocks for different SwiftSyntax versions

Testing (Required)

  • Updated existing unit tests to verify macro functionality with SwiftSyntax 600+
  • Added new test case to verify proper error message is shown when SwiftSyntax version is below 600
  • All tests pass with both SwiftSyntax 509.x and 600+ versions
  • Manual testing confirmed that:
    • The macro works correctly with SwiftSyntax 600+
    • Appropriate error message is displayed for older versions

Review Notes

  • This is a compatibility fix to ensure the macro works across different SwiftSyntax versions
  • The lexicalContext API provides better context information for macro expansion but is only available in newer versions
  • This approach allows the library to maintain backward compatibility while leveraging newer APIs when available
  • Future consideration: When minimum SwiftSyntax version is raised to 600+, the conditional compilation can be removed

@ElonPark ElonPark self-assigned this Sep 17, 2025
@ElonPark ElonPark added the Bug Something isn't working label Sep 17, 2025
@ElonPark ElonPark added this to the v4.7.0 milestone Sep 17, 2025

@jaxtynSong jaxtynSong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍

@ElonPark ElonPark merged commit d608169 into main Sep 18, 2025
4 checks passed
@ElonPark ElonPark deleted the bug/elon/fix-swift-syntax-5-error branch September 18, 2025 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants