Skip to content

Commit edc83c8

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

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,25 @@ final class TypeTests: ParserTestCase {
565565
assertParse("struct S : nonisolated P {}")
566566
assertParse("let _ = [nonisolated()]")
567567

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

0 commit comments

Comments
 (0)