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

[SR-13752] SwiftSyntax unrecognized [self = foo] #314

Closed
keith opened this issue Oct 19, 2020 · 2 comments
Closed

[SR-13752] SwiftSyntax unrecognized [self = foo] #314

keith opened this issue Oct 19, 2020 · 2 comments
Labels
bug Something isn't working swift-format SwiftSyntax

Comments

@keith
Copy link
Collaborator

keith commented Oct 19, 2020

Previous ID SR-13752
Radar rdar://problem/70446049
Original Reporter @keith
Type Bug
Environment

swift-syntax d518259
macOS

Additional Detail from JIRA
Votes 0
Component/s swift-format, SwiftSyntax
Labels Bug
Assignee None
Priority Medium

md5: f216403cfbb1ce9b46bd15205e13ac1e

Issue Description:

With this syntax:

let foo = "hi"
let bar = { [self = foo] in
    print(self)
}

swift-format errors with:

% .build/debug/swift-format lint /tmp/foo.swift
/tmp/foo.swift:2:11: error: file contains invalid or unrecognized Swift syntax.

Based on some cursory look it seems that the issue here is from SwiftSyntax and not swift-format

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
@allevato
Copy link
Collaborator

This appears to no longer be an issue on main using the new SwiftParser:

$ .build/debug/swift-format <<'EOF'
heredoc> let foo = "hi"
let bar = { [self = foo] in
    print(self)
}
heredoc> EOF

Output:

let foo = "hi"
let bar = { [self = foo] in
  print(self)
}

Generated parse tree:

SourceFileSyntax children=2
  0: CodeBlockItemListSyntax children=2
    0: CodeBlockItemSyntax children=1
      0: VariableDeclSyntax children=2
        0: letKeyword
        1: PatternBindingListSyntax children=1
          0: PatternBindingSyntax children=2
            0: IdentifierPatternSyntax children=1
              0: identifier("foo")
            1: InitializerClauseSyntax children=2
              0: equal
              1: StringLiteralExprSyntax children=3
                0: stringQuote
                1: StringLiteralSegmentsSyntax children=1
                  0: StringSegmentSyntax children=1
                    0: stringSegment("hi")
                2: stringQuote
    1: CodeBlockItemSyntax children=1
      0: VariableDeclSyntax children=2
        0: letKeyword
        1: PatternBindingListSyntax children=1
          0: PatternBindingSyntax children=2
            0: IdentifierPatternSyntax children=1
              0: identifier("bar")
            1: InitializerClauseSyntax children=2
              0: equal
              1: ClosureExprSyntax children=4
                0: leftBrace
                1: ClosureSignatureSyntax children=2
                  0: ClosureCaptureSignatureSyntax children=3
                    0: leftSquareBracket
                    1: ClosureCaptureItemListSyntax children=1
                      0: ClosureCaptureItemSyntax children=4
                        0: TokenListSyntax
                        1: selfKeyword
                        2: equal
                        3: IdentifierExprSyntax children=1
                          0: identifier("foo")
                    2: rightSquareBracket
                  1: inKeyword
                2: CodeBlockItemListSyntax children=1
                  0: CodeBlockItemSyntax children=1
                    0: FunctionCallExprSyntax children=4
                      0: IdentifierExprSyntax children=1
                        0: identifier("print")
                      1: leftParen
                      2: TupleExprElementListSyntax children=1
                        0: TupleExprElementSyntax children=1
                          0: IdentifierExprSyntax children=1
                            0: selfKeyword
                      3: rightParen
                3: rightBrace
  1: eof

@allevato allevato closed this as not planned Won't fix, can't repro, duplicate, stale Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working swift-format SwiftSyntax
Projects
None yet
Development

No branches or pull requests

3 participants