Skip to content

SwiftParser allows inconsistent spacing around = #815

Closed
@allevato

Description

@allevato

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SwiftParserBugs in the (new) Parser written in SwiftbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions