Skip to content

Unexpected macro parsing #1409

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

Closed
TiagoMaiaL opened this issue Mar 15, 2023 · 2 comments
Closed

Unexpected macro parsing #1409

TiagoMaiaL opened this issue Mar 15, 2023 · 2 comments
Labels
bug Something isn't working SwiftParser Bugs in the (new) Parser written in Swift

Comments

@TiagoMaiaL
Copy link
Contributor

Issue Kind

Parse of Valid Source Produced Invalid Syntax Tree

Source Code

struct S {
#if swift(>=2.2)
  let x: Int
#else
  // There should be no error here.
  let x: @#$()%&*)@#$(%&*
#endif
}

Description

The above code is from the swift project, and can be found here.

Instead of parsing x as a constant declaration, with @#$()%&*)@#$(%&* as its type, the above code only parses let x: @ as a variableDecl. The rest of the type is parsed in a wrong way, and the following #$() sequence is parsed as a macroExpansionDecl.

The following test fails:

  func testIfConfigExpr36() {
    AssertParse(
      """
      struct S {
      #if swift(>=2.2)
        let x: Int
      #else
        // There should be no error here.
        let x: @#$()%&*)@#$(%&*
      #endif
      }
      """
    )
  }
@TiagoMaiaL TiagoMaiaL added bug Something isn't working SwiftParser Bugs in the (new) Parser written in Swift labels Mar 15, 2023
@ahoppen
Copy link
Member

ahoppen commented Mar 15, 2023

rdar://106732638

@ahoppen
Copy link
Member

ahoppen commented Mar 16, 2023

This behaves as expected because the parser doesn’t evaluate #if directives. The warnings in if directives will be emitted when invoking swift-parser-cli but will be hidden when SwiftParser is invoked from the compiler here: https://github.com/apple/swift/blob/8fa394f441e24e82e3da7d33a404ebe3ac7ea30a/lib/ASTGen/Sources/ASTGen/SourceFile.swift#L91-L96

@ahoppen ahoppen closed this as completed Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SwiftParser Bugs in the (new) Parser written in Swift
Projects
None yet
Development

No branches or pull requests

2 participants