Skip to content

SwiftParser allows inconsistent spacing around = #815

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
allevato opened this issue Sep 19, 2022 · 3 comments
Closed

SwiftParser allows inconsistent spacing around = #815

allevato opened this issue Sep 19, 2022 · 3 comments
Labels
bug Something isn't working SwiftParser Bugs in the (new) Parser written in Swift

Comments

@allevato
Copy link
Member

Issue Kind

Bad Diagnostic Produced

Source Code

let x= 5

Description

In swiftc, this produces an error:

$ swiftc -Xfrontend -emit-syntax - <<'EOF'
heredoc> let x= 5
heredoc> EOF

<stdin>:1:6: error: '=' must have consistent whitespace on both sides
let x= 5
     ^

In SwiftParser, a valid syntax tree is produced with no diagnostics:

$ .build/debug/swift-parser-test print-diags <<'EOF'
let x= 5
EOF

No diagnostics produced
$ .build/debug/swift-parser-test dump-tree <<'EOF'
let x= 5
EOF

SourceFileSyntax children=2
  0: CodeBlockItemListSyntax children=1
    0: CodeBlockItemSyntax children=1
      0: VariableDeclSyntax children=2
        0: letKeyword
        1: PatternBindingListSyntax children=1
          0: PatternBindingSyntax children=2
            0: IdentifierPatternSyntax children=1
              0: identifier("x")
            1: InitializerClauseSyntax children=2
              0: equal
              1: IntegerLiteralExprSyntax children=1
                0: integerLiteral("5")
  1: eof

This is not limited to just InitializerClauseSyntax bindings; assignments to already-declared variables via AssignmentExprSyntax exhibit the same behavior.

@allevato allevato added bug Something isn't working SwiftParser Bugs in the (new) Parser written in Swift labels Sep 19, 2022
@ahoppen
Copy link
Member

ahoppen commented Sep 20, 2022

rdar://100158607

@kimdv
Copy link
Contributor

kimdv commented Apr 26, 2023

@allevato I think this was resolved in #1456

@allevato
Copy link
Member Author

Yes, this is now fixed at HEAD:

$ .build/debug/swift-parser-cli print-diags <<'EOF'
let x= 5
x =5
EOF
=== stdin:1 ===
1 │ let x= 5
  │      ╰─ error: '=' must have consistent whitespace on both sides
2 │ x =5
  │    ╰─ error: '=' must have consistent whitespace on both sides
3 │

Thank you @kimdv!

Fixed by #1456.

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

3 participants