[Parse] Fix variable identifier parsing including code on newline as part of the identifier (#61036)

This commit is contained in:
Suyash Srijan
2022-09-12 23:05:20 +01:00
committed by GitHub
parent fa82a6ee42
commit fd8d7afc5b
2 changed files with 15 additions and 1 deletions

View File

@@ -1112,7 +1112,8 @@ ParserResult<Pattern> Parser::parsePattern() {
PatternCtx.setCreateSyntax(SyntaxKind::IdentifierPattern);
Identifier name;
SourceLoc loc = consumeIdentifier(name, /*diagnoseDollarPrefix=*/true);
if (Tok.isIdentifierOrUnderscore() && !Tok.isContextualDeclKeyword())
if (Tok.isIdentifierOrUnderscore() && !Tok.isContextualDeclKeyword() &&
!Tok.isAtStartOfLine())
diagnoseConsecutiveIDs(name.str(), loc,
introducer == VarDecl::Introducer::Let
? "constant" : "variable");

View File

@@ -47,3 +47,16 @@ _ = sil_witness_table // expected-error {{cannot find 'sil_witness_table' in sco
_ = sil_default_witness_table // expected-error {{cannot find 'sil_default_witness_table' in scope}}
_ = sil_coverage_map // expected-error {{cannot find 'sil_coverage_map' in scope}}
_ = sil_scope // expected-error {{cannot find 'sil_scope' in scope}}
// https://github.com/apple/swift/issues/57542
// Make sure we do not parse the '_' on the newline as being part of the 'variable' identifier on the line before.
@propertyWrapper
struct Wrapper {
var wrappedValue = 0
}
func localScope() {
@Wrapper var variable
_ = 0
}