Skip to content

Commit 5f7d382

Browse files
authored
Merge pull request #3006 from DougGregor/se-0458-unsafe-eof
[SE-0458] Disambiguation at the end of the file
2 parents af7c0c6 + d422983 commit 5f7d382

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ extension Parser {
463463
// - Subscript vs. array or dictionary expression
464464
|| (self.peek(isAt: .period, .leftParen, .leftSquare) && self.peek().leadingTriviaByteLength == 0
465465
&& self.currentToken.trailingTriviaByteLength == 0)
466+
// End of file
467+
|| self.peek(isAt: .endOfFile)
466468
{
467469
break EXPR_PREFIX
468470
}

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,6 +2335,23 @@ final class StatementExpressionTests: ParserTestCase {
23352335
expression: ArrayExprSyntax(expressions: [])
23362336
)
23372337
)
2338+
2339+
assertParse(
2340+
#"""
2341+
func f() {
2342+
"\(unsafe)"
2343+
}
2344+
"""#,
2345+
substructure: DeclReferenceExprSyntax(baseName: .identifier("unsafe"))
2346+
)
2347+
2348+
assertParse(
2349+
"""
2350+
a = 1️⃣unsafe
2351+
""",
2352+
substructure: DeclReferenceExprSyntax(baseName: .identifier("unsafe")),
2353+
substructureAfterMarker: "1️⃣"
2354+
)
23382355
}
23392356

23402357
func testUnterminatedInterpolationAtEndOfMultilineStringLiteral() {

0 commit comments

Comments
 (0)