Skip to content
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

Remove CanImportExprSyntax and provide API to interpret an ExprSyntax as a VersionTupleSyntax #1972

Closed
ahoppen opened this issue Aug 1, 2023 · 1 comment · Fixed by #2025

Comments

@ahoppen
Copy link
Collaborator

ahoppen commented Aug 1, 2023

canImport inside of #if should get parsed the same as in a normal expression position, eliminating the need for CanImportExprSyntax (sparked by link). This means that the parser won’t be able to generate diagnostics for invalid version numbers inside canImport anymore.

Instead, we should have a function on ExprSyntax that interprets the expression (which would be a FloatingLiteralExprSyntax for eg. 1.2) as a VersionTupleSyntax. If the ExprSyntax doesn’t represent a version, that function should return a list of diagnostics. SwiftIfConfig would then call that getter and would be responsible for reporting any errors that occur from interpreting the ExprSyntax of the _version argument as VersionTupleSyntax.

@ahoppen ahoppen changed the title Remove CanImportExprSyntax and provide API to interpret an ExprSyntax as a VersionTupleSyntax Remove CanImportExprSyntax and provide API to interpret an ExprSyntax as a VersionTupleSyntax Aug 1, 2023
@ahoppen
Copy link
Collaborator Author

ahoppen commented Aug 2, 2023

Tracked in Apple’s issue tracker as rdar://113236781

ahoppen added a commit to StevenWong12/swift-syntax that referenced this issue Mar 15, 2024
…ression node

To make it easier to interpret the version passed to `canImport(MyModule, _version: <#version#>)`, add `ExprSyntax.interpretedAsVersionTuple` that takes eg. `1.2.3`, which got parsed as a member access `3` to the `1.2` float literal and re-parses it as a `VersionTupleSyntax`.

This relaxation also allows string literals as version parameters to `#if canImport`.

Fixes apple#1972
rdar://121070235

Co-Authored-By: Ziyang Huang <stevenhuang12@outlook.com>
ahoppen added a commit to ahoppen/swift-syntax that referenced this issue Mar 19, 2024
…ression node

To make it easier to interpret the version passed to `canImport(MyModule, _version: <#version#>)`, add `ExprSyntax.interpretedAsVersionTuple` that takes eg. `1.2.3`, which got parsed as a member access `3` to the `1.2` float literal and re-parses it as a `VersionTupleSyntax`.

This relaxation also allows string literals as version parameters to `#if canImport`.

Fixes apple#1972
rdar://121070235

Co-Authored-By: Ziyang Huang <stevenhuang12@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant