Skip to content

Commit cf27f49

Browse files
authored
Merge pull request #41024 from hborla/5.6-fix-any-expr-parsing
[5.6][Parser] Don't parse 'any identifier' as a type when the identifier is on the next line.
2 parents 7d9a1b6 + 6b828fe commit cf27f49

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,8 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
16271627

16281628
// 'any' followed by another identifier is an existential type.
16291629
if (Tok.isContextualKeyword("any") &&
1630-
peekToken().is(tok::identifier)) {
1630+
peekToken().is(tok::identifier) &&
1631+
!peekToken().isAtStartOfLine()) {
16311632
ParserResult<TypeRepr> ty = parseType();
16321633
auto *typeExpr = new (Context) TypeExpr(ty.get());
16331634
return makeParserResult(typeExpr);

test/type/explicit_existential.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,12 @@ func testAnyTypeExpr() {
213213
// expected-note@+1 {{use '.self' to reference the type object}}
214214
let invalid = any P
215215
test(invalid)
216+
217+
// Make sure 'any' followed by an identifier
218+
// on the next line isn't parsed as a type.
219+
func doSomething() {}
220+
221+
let any = 10
222+
let _ = any
223+
doSomething()
216224
}

0 commit comments

Comments
 (0)