Skip to content

Commit 613c072

Browse files
committed
Ensure that "single unlabeled argument" checks for a nil label
1 parent 24ead55 commit 613c072

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Sources/SwiftIfConfig/SyntaxLiteralUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension TupleExprSyntax {
2828
extension LabeledExprListSyntax {
2929
/// If this list is a single, unlabeled expression, return it.
3030
var singleUnlabeledExpression: ExprSyntax? {
31-
guard count == 1, let element = first else { return nil }
31+
guard count == 1, let element = first, element.label == nil else { return nil }
3232
return element.expression
3333
}
3434
}

Tests/SwiftIfConfigTest/EvaluateTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,19 @@ public class EvaluateTests: XCTestCase {
308308
)
309309
]
310310
)
311+
312+
assertIfConfig(
313+
"swift(version: >=5.5)",
314+
.unparsed,
315+
diagnostics: [
316+
DiagnosticSpec(
317+
message: "swift requires a single unlabeled argument for the version comparison (>= or <= a version)",
318+
line: 1,
319+
column: 1,
320+
severity: .error
321+
)
322+
]
323+
)
311324
}
312325

313326
func testCanImport() throws {

0 commit comments

Comments
 (0)