Skip to content

Commit a5afdab

Browse files
committed
Improve and test diagnostic for compiler version component being out-of-range
The compiler diagnostic here wasn't great; improve it.
1 parent 06dd06e commit a5afdab

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Sources/SwiftIfConfig/IfConfigDiagnostic.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ enum IfConfigDiagnostic: Error, CustomStringConvertible {
6060
case .emptyVersionComponent(syntax: _):
6161
return "found empty version component"
6262

63-
case .compilerVersionOutOfRange(value: _, upperLimit: let upperLimit, syntax: _):
64-
// FIXME: This matches the C++ implementation, but it would be more useful to
65-
// provide the actual value as-written and avoid the mathy [0, N] syntax.
66-
return "compiler version component out of range: must be in [0, \(upperLimit)]"
63+
case .compilerVersionOutOfRange(value: let value, upperLimit: let upperLimit, syntax: _):
64+
return "compiler version component '\(value)' is not in the allowed range 0...\(upperLimit)"
6765

6866
case .compilerVersionSecondComponentNotWildcard(syntax: _):
6967
return "the second version component is not used for comparison in legacy compiler versions"

Tests/SwiftIfConfigTest/EvaluateTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,19 @@ public class EvaluateTests: XCTestCase {
323323
)
324324
]
325325
)
326+
327+
assertIfConfig(
328+
#"_compiler_version("5009.*.1000")"#,
329+
.unparsed,
330+
diagnostics: [
331+
DiagnosticSpec(
332+
message: "compiler version component '1000' is not in the allowed range 0...999",
333+
line: 1,
334+
column: 20,
335+
severity: .error
336+
)
337+
]
338+
)
326339
}
327340

328341
func testCanImport() throws {

0 commit comments

Comments
 (0)