Skip to content

Commit 1df326d

Browse files
committed
[SwiftParser] Account for a newline between nonisolated and (
1 parent 9ffe4b8 commit 1df326d

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Sources/SwiftParser/Types.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,6 @@ extension Parser.Lookahead {
689689

690690
mutating func skipTypeAttributeList() {
691691
var specifierProgress = LoopProgressCondition()
692-
// TODO: Can we model isolated/_const so that they're specified in both canParse* and parse*?
693692
while canHaveParameterSpecifier,
694693
self.at(anyIn: SimpleTypeSpecifierSyntax.SpecifierOptions.self) != nil
695694
|| self.at(.keyword(.nonisolated), .keyword(.dependsOn)),
@@ -701,7 +700,7 @@ extension Parser.Lookahead {
701700

702701
// The argument is missing but it still could be a valid modifier,
703702
// i.e. `nonisolated` in an inheritance clause.
704-
guard self.at(.leftParen) else {
703+
guard self.at(.leftParen), !self.currentToken.isAtStartOfLine else {
705704
continue
706705
}
707706

@@ -1178,6 +1177,11 @@ extension Parser {
11781177
break SPECIFIER_PARSING
11791178
}
11801179
} else if self.at(.keyword(.nonisolated)) {
1180+
// If '(' is located on the new line 'nonisolated' cannot be parsed
1181+
// as a specifier.
1182+
if self.peek(isAt: .leftParen) && self.peek().isAtStartOfLine {
1183+
break SPECIFIER_PARSING
1184+
}
11811185
specifiers.append(parseNonisolatedTypeSpecifier())
11821186
} else {
11831187
break SPECIFIER_PARSING

Tests/SwiftParserTest/TypeTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,28 @@ final class TypeTests: ParserTestCase {
565565
assertParse("struct S : nonisolated P {}")
566566
assertParse("let _ = [nonisolated()]")
567567

568+
assertParse(
569+
"""
570+
let x: nonisolated
571+
(hello)
572+
"""
573+
)
574+
575+
assertParse(
576+
"""
577+
struct S: nonisolated
578+
P {
579+
}
580+
"""
581+
)
582+
583+
assertParse(
584+
"""
585+
let x: nonisolated
586+
(Int) async -> Void = {}
587+
"""
588+
)
589+
568590
assertParse(
569591
"Foo<Int, nonisolated1️⃣ @Sendable (Int, inout (any Actor)?) async throws -> Void>()",
570592
diagnostics: [

0 commit comments

Comments
 (0)