Skip to content

SwiftParser allows closures in condition lists where the compiler doesn't #795

@allevato

Description

@allevato

Issue Kind

Bad Diagnostic Produced

Source Code

if {x}() {}
if x.map{$0} {}

Description

While I would love to have these examples permitted, Swift forbids them but they currently succeed in the new Swift parser without diagnostics and produce the following valid parse tree:

SourceFileSyntax children=2
  0: CodeBlockItemListSyntax children=2        // if {x}() {}
    0: CodeBlockItemSyntax children=1
      0: IfStmtSyntax children=3
        0: ifKeyword
        1: ConditionElementListSyntax children=1
          0: ConditionElementSyntax children=1
            0: FunctionCallExprSyntax children=4
              0: ClosureExprSyntax children=3
                0: leftBrace
                1: CodeBlockItemListSyntax children=1
                  0: CodeBlockItemSyntax children=1
                    0: IdentifierExprSyntax children=1
                      0: identifier("x")
                2: rightBrace
              1: leftParen
              2: TupleExprElementListSyntax
              3: rightParen
        2: CodeBlockSyntax children=3
          0: leftBrace
          1: CodeBlockItemListSyntax
          2: rightBrace
    1: CodeBlockItemSyntax children=1        // if x.map{$0} {}
      0: IfStmtSyntax children=3
        0: ifKeyword
        1: ConditionElementListSyntax children=1
          0: ConditionElementSyntax children=1
            0: FunctionCallExprSyntax children=3
              0: MemberAccessExprSyntax children=3
                0: IdentifierExprSyntax children=1
                  0: identifier("x")
                1: period
                2: identifier("map")
              1: TupleExprElementListSyntax
              2: ClosureExprSyntax children=3
                0: leftBrace
                1: CodeBlockItemListSyntax children=1
                  0: CodeBlockItemSyntax children=1
                    0: IdentifierExprSyntax children=1
                      0: dollarIdentifier("$0")
                2: rightBrace
        2: CodeBlockSyntax children=3
          0: leftBrace
          1: CodeBlockItemListSyntax
          2: rightBrace
  1: eof

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