Skip to content

Commit b57568f

Browse files
committed
guard nonisolated(unsafe) by experimental feature
1 parent c04e83d commit b57568f

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Sources/SwiftParser/ExperimentalFeatures.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ extension Parser.ExperimentalFeatures {
2626

2727
/// Whether to enable the parsing of 'then' statements.
2828
public static let thenStatements = Self(rawValue: 1 << 1)
29+
30+
/// Whether to enable the parsing of strict concurrency for globals.
31+
public static let globalConcurrency = Self(rawValue: 1 << 2)
2932
}

Sources/SwiftParser/Modifiers.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ extension Parser {
6161
case (.declarationModifier(.unowned), let handle)?:
6262
elements.append(self.parseUnownedModifier(handle))
6363
case (.declarationModifier(.nonisolated), let handle)?:
64-
elements.append(parseNonisolatedModifier(handle))
64+
if experimentalFeatures.contains(.globalConcurrency) {
65+
elements.append(parseNonisolatedModifier(handle))
66+
} else {
67+
let (unexpectedBeforeKeyword, keyword) = self.eat(handle)
68+
elements.append(RawDeclModifierSyntax(unexpectedBeforeKeyword, name: keyword, detail: nil, arena: self.arena))
69+
}
6570
case (.declarationModifier(.final), let handle)?,
6671
(.declarationModifier(.required), let handle)?,
6772
(.declarationModifier(.optional), let handle)?,

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ final class DeclarationTests: ParserTestCase {
210210
nonisolated(unsafe) var c: Int { 0 }
211211
nonisolated(unsafe) let d = 0
212212
}
213-
"""
213+
""",
214+
experimentalFeatures: [.globalConcurrency]
214215
)
215216
}
216217

0 commit comments

Comments
 (0)