Skip to content

Commit 7262c1a

Browse files
committed
[SE-0458] Disambiguate existing uses of unsafe better
Only treat `unsafe` as starting an unsafe expression if the following token is on the same line and isn't a `)`. The former is in line with how we handle other modifier expressions like this, and the latter is because of the archaic `@MainActor(unsafe)`.
1 parent 14ea0a4 commit 7262c1a

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ extension Parser {
445445
)
446446
)
447447
case (.unsafe, let handle)?:
448+
if self.peek().isAtStartOfLine || self.peek(isAt: .rightParen) {
449+
break EXPR_PREFIX
450+
}
451+
448452
let unsafeTok = self.eat(handle)
449453
let sub = self.parseSequenceExpressionElement(
450454
flavor: flavor,

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,24 +2200,11 @@ final class StatementExpressionTests: ParserTestCase {
22002200
assertParse(
22012201
"""
22022202
func f() {
2203-
let x = unsafe1️⃣ y
2203+
let x = unsafe
2204+
y
22042205
}
22052206
""",
2206-
diagnostics: [
2207-
DiagnosticSpec(
2208-
message: "consecutive statements on a line must be separated by newline or ';'",
2209-
fixIts: [
2210-
"insert newline",
2211-
"insert ';'",
2212-
]
2213-
)
2214-
],
2215-
fixedSource: """
2216-
func f() {
2217-
let x = unsafe
2218-
y
2219-
}
2220-
"""
2207+
substructure: DeclReferenceExprSyntax(baseName: .identifier("unsafe"))
22212208
)
22222209
}
22232210

0 commit comments

Comments
 (0)