Skip to content

Commit 65f6ea3

Browse files
authored
Merge pull request swiftlang#41023 from hborla/fix-any-expr-parsing
[Parser] Don't parse 'any identifier' as a type when the identifier is on the next line.
2 parents 0472c0d + 1acc9c3 commit 65f6ea3

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
@@ -224,6 +224,14 @@ func testAnyTypeExpr() {
224224
// expected-note@+1 {{use '.self' to reference the type object}}
225225
let invalid = any P
226226
test(invalid)
227+
228+
// Make sure 'any' followed by an identifier
229+
// on the next line isn't parsed as a type.
230+
func doSomething() {}
231+
232+
let any = 10
233+
let _ = any
234+
doSomething()
227235
}
228236

229237
func hasInvalidExistential(_: any DoesNotExistIHope) {}

0 commit comments

Comments
 (0)