Skip to content

Commit 35a9cde

Browse files
committed
[SwiftParser] Allow nonisolated to accept nonsending modifier
1 parent 491c5c9 commit 35a9cde

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ public enum Keyword: CaseIterable {
210210
case none
211211
case nonisolated
212212
case nonmutating
213+
case nonsending
213214
case objc
214215
case obsoleted
215216
case of
@@ -551,6 +552,8 @@ public enum Keyword: CaseIterable {
551552
return KeywordSpec("nonisolated")
552553
case .nonmutating:
553554
return KeywordSpec("nonmutating")
555+
case .nonsending:
556+
return KeywordSpec("nonsending")
554557
case .objc:
555558
return KeywordSpec("objc")
556559
case .obsoleted:

Sources/SwiftParser/Modifiers.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ extension Parser {
236236
let detail: RawDeclModifierDetailSyntax?
237237
if self.at(.leftParen) {
238238
let (unexpectedBeforeLeftParen, leftParen) = self.expect(.leftParen)
239-
let (unexpectedBeforeDetailToken, detailToken) = self.expect(TokenSpec(.unsafe, remapping: .identifier))
239+
let (unexpectedBeforeDetailToken, detailToken) = self.expect(
240+
TokenSpec(.unsafe, remapping: .identifier),
241+
TokenSpec(.nonsending, remapping: .identifier),
242+
default: TokenSpec(.identifier)
243+
)
240244
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
241245
detail = RawDeclModifierDetailSyntax(
242246
unexpectedBeforeLeftParen,

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ enum TokenPrecedence: Comparable {
326326
.module,
327327
.noasync,
328328
.none,
329+
.nonsending,
329330
.obsoleted,
330331
.of,
331332
.Protocol,

Sources/SwiftSyntax/generated/Keyword.swift

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ final class DeclarationTests: ParserTestCase {
261261
""",
262262
diagnostics: [
263263
DiagnosticSpec(
264-
message: "expected 'unsafe' in modifier",
265-
fixIts: ["replace 'safe' with 'unsafe'"]
264+
message: "expected identifier in modifier",
265+
fixIts: ["replace 'safe' with identifier"]
266266
)
267267
],
268268
fixedSource: """
@@ -271,7 +271,36 @@ final class DeclarationTests: ParserTestCase {
271271
struct A {
272272
nonisolated(unsafe) let b = 0
273273
nonisolated(unsafe) var c: Int { 0 }
274-
nonisolated(unsafe) let d = 0
274+
nonisolated(<#identifier#>) let d = 0
275+
}
276+
"""
277+
)
278+
}
279+
280+
func testNonisolatedNonSendingParsing() {
281+
assertParse(
282+
"""
283+
nonisolated(nonsending) let a = 0
284+
285+
struct A {
286+
nonisolated(nonsending) let b = 0
287+
nonisolated(nonsending) var c: Int { 0 }
288+
nonisolated(1️⃣sending) let d = 0
289+
}
290+
""",
291+
diagnostics: [
292+
DiagnosticSpec(
293+
message: "expected identifier in modifier",
294+
fixIts: ["replace 'sending' with identifier"]
295+
)
296+
],
297+
fixedSource: """
298+
nonisolated(nonsending) let a = 0
299+
300+
struct A {
301+
nonisolated(nonsending) let b = 0
302+
nonisolated(nonsending) var c: Int { 0 }
303+
nonisolated(<#identifier#>) let d = 0
275304
}
276305
"""
277306
)

0 commit comments

Comments
 (0)