Skip to content

reject invalid arguments to nonisolated contextual keyword #2335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Sources/SwiftParser/Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ extension Parser {
}

extension Parser {
mutating func parseModifierDetail(_ keyword: Keyword) -> RawDeclModifierDetailSyntax {
mutating func parseModifierDetail() -> RawDeclModifierDetailSyntax {
let (unexpectedBeforeLeftParen, leftParen) = self.expect(.leftParen)
let (unexpectedBeforeDetailToken, detailToken) = self.expect(.identifier, TokenSpec(keyword, remapping: .identifier), default: .identifier)
let (unexpectedBeforeDetailToken, detailToken) = self.expect(.identifier, TokenSpec(.set, remapping: .identifier), default: .identifier)
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
return RawDeclModifierDetailSyntax(
unexpectedBeforeLeftParen,
Expand All @@ -119,7 +119,7 @@ extension Parser {

let detail: RawDeclModifierDetailSyntax?
if self.at(.leftParen) {
detail = self.parseModifierDetail(.set)
detail = self.parseModifierDetail()
} else {
detail = nil
}
Expand Down Expand Up @@ -224,7 +224,18 @@ extension Parser {

let detail: RawDeclModifierDetailSyntax?
if self.at(.leftParen) {
detail = self.parseModifierDetail(.unsafe)
let (unexpectedBeforeLeftParen, leftParen) = self.expect(.leftParen)
let (unexpectedBeforeDetailToken, detailToken) = self.expect(TokenSpec(.unsafe, remapping: .identifier))
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
detail = RawDeclModifierDetailSyntax(
unexpectedBeforeLeftParen,
leftParen: leftParen,
unexpectedBeforeDetailToken,
detail: detailToken,
unexpectedBeforeRightParen,
rightParen: rightParen,
arena: self.arena
)
} else {
detail = nil
}
Expand Down
18 changes: 17 additions & 1 deletion Tests/SwiftParserTest/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,24 @@ final class DeclarationTests: ParserTestCase {
struct A {
nonisolated(unsafe) let b = 0
nonisolated(unsafe) var c: Int { 0 }
nonisolated(1️⃣safe) let d = 0
}
"""
""",
diagnostics: [
DiagnosticSpec(
message: "expected 'unsafe' in modifier",
fixIts: ["replace 'safe' with 'unsafe'"]
)
],
fixedSource: """
nonisolated(unsafe) let a = 0
struct A {
nonisolated(unsafe) let b = 0
nonisolated(unsafe) var c: Int { 0 }
nonisolated(unsafe) let d = 0
}
"""
)
}

Expand Down