Skip to content

Commit 7652336

Browse files
committed
Don’t drop module selector in bad generic arg list
The code assumed that dropping a `MissingTypeSyntax` wouldn’t lose any tokens.
1 parent fbede44 commit 7652336

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Sources/SwiftParser/Types.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,9 @@ extension Parser {
448448
repeat {
449449
let argument = self.parseGenericArgumentType()
450450

451-
if arguments.isEmpty, argument.raw.is(RawMissingTypeSyntax.self) {
451+
if arguments.isEmpty, let missingType = argument.raw.as(RawMissingTypeSyntax.self),
452+
missingType.moduleSelector == nil
453+
{
452454
break
453455
}
454456

Tests/SwiftParserTest/AttributeTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,33 @@ final class AttributeTests: ParserTestCase {
205205
experimentalFeatures: [.moduleSelector]
206206
)
207207

208+
// Found through mutation testing.
209+
assertParse(
210+
"""
211+
@objc<1️⃣::2️⃣:x::)
212+
func f(_: Int, _: Int, _: Int, _: Int, _: Int) { }
213+
""",
214+
diagnostics: [
215+
DiagnosticSpec(
216+
message: "expected module name in module selector",
217+
fixIts: ["insert module name"]
218+
),
219+
DiagnosticSpec(
220+
message: "expected type and '>' to end generic argument clause",
221+
fixIts: ["insert type and '>'"]
222+
),
223+
DiagnosticSpec(
224+
locationMarker: "2️⃣",
225+
message: "unexpected code ':x::)' in function"
226+
),
227+
],
228+
fixedSource: """
229+
@objc<<#identifier#>::<#type#>>:x::)
230+
func f(_: Int, _: Int, _: Int, _: Int, _: Int) { }
231+
""",
232+
experimentalFeatures: [.moduleSelector]
233+
)
234+
208235
assertParse(
209236
"""
210237
@objc(_:)

0 commit comments

Comments
 (0)