Skip to content

Commit fd8d7af

Browse files
authored
[Parse] Fix variable identifier parsing including code on newline as part of the identifier (#61036)
1 parent fa82a6e commit fd8d7af

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/Parse/ParsePattern.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,8 @@ ParserResult<Pattern> Parser::parsePattern() {
11121112
PatternCtx.setCreateSyntax(SyntaxKind::IdentifierPattern);
11131113
Identifier name;
11141114
SourceLoc loc = consumeIdentifier(name, /*diagnoseDollarPrefix=*/true);
1115-
if (Tok.isIdentifierOrUnderscore() && !Tok.isContextualDeclKeyword())
1115+
if (Tok.isIdentifierOrUnderscore() && !Tok.isContextualDeclKeyword() &&
1116+
!Tok.isAtStartOfLine())
11161117
diagnoseConsecutiveIDs(name.str(), loc,
11171118
introducer == VarDecl::Introducer::Let
11181119
? "constant" : "variable");

test/Parse/identifiers.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,16 @@ _ = sil_witness_table // expected-error {{cannot find 'sil_witness_table' in sco
4747
_ = sil_default_witness_table // expected-error {{cannot find 'sil_default_witness_table' in scope}}
4848
_ = sil_coverage_map // expected-error {{cannot find 'sil_coverage_map' in scope}}
4949
_ = sil_scope // expected-error {{cannot find 'sil_scope' in scope}}
50+
51+
// https://github.com/apple/swift/issues/57542
52+
// Make sure we do not parse the '_' on the newline as being part of the 'variable' identifier on the line before.
53+
54+
@propertyWrapper
55+
struct Wrapper {
56+
var wrappedValue = 0
57+
}
58+
59+
func localScope() {
60+
@Wrapper var variable
61+
_ = 0
62+
}

0 commit comments

Comments
 (0)