Skip to content

Commit d5e3717

Browse files
committed
Slight changes in diagnostic wording to more closely match the compiler
1 parent e4f5517 commit d5e3717

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

Sources/SwiftIfConfig/IfConfigError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ enum IfConfigError: Error, CustomStringConvertible {
6767
return "canImport requires a module name"
6868

6969
case .canImportLabel(syntax: _):
70-
return "2nd parameter of canImport should be labeled as _version or _underlyingVersion"
70+
return "second parameter of canImport should be labeled as _version or _underlyingVersion"
7171

7272
case .canImportTwoParameters(syntax: _):
7373
return "canImport can take only two parameters"

Sources/SwiftIfConfig/IfConfigEvaluation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ func evaluateIfConfig(
374374
return recordError(.canImportMissingModule(syntax: ExprSyntax(call)))
375375
}
376376

377+
if call.arguments.count > 2 {
378+
return recordError(.canImportTwoParameters(syntax: ExprSyntax(call)))
379+
}
380+
377381
// FIXME: This is a gross hack. Actually look at the sequence of
378382
// `MemberAccessExprSyntax` nodes and pull out the identifiers.
379383
let importPath = firstArg.expression.trimmedDescription.split(separator: ".")
@@ -423,10 +427,6 @@ func evaluateIfConfig(
423427
assert(secondArg.label?.text == "_underlyingVersion")
424428
version = .underlyingVersion(versionTuple)
425429
}
426-
427-
if call.arguments.count > 2 {
428-
return recordError(.canImportTwoParameters(syntax: ExprSyntax(call)))
429-
}
430430
} else {
431431
version = .unversioned
432432
}

Tests/SwiftIfConfigTest/EvaluateTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,32 @@ public class EvaluateTests: XCTestCase {
277277
)
278278
]
279279
)
280+
281+
assertIfConfig(
282+
"canImport(A, 2.2)",
283+
.unparsed,
284+
diagnostics: [
285+
DiagnosticSpec(
286+
message: #"second parameter of canImport should be labeled as _version or _underlyingVersion"#,
287+
line: 1,
288+
column: 14,
289+
severity: .error
290+
)
291+
]
292+
)
293+
294+
assertIfConfig(
295+
"canImport(A, 2.2, 1.1)",
296+
.unparsed,
297+
diagnostics: [
298+
DiagnosticSpec(
299+
message: #"canImport can take only two parameters"#,
300+
line: 1,
301+
column: 1,
302+
severity: .error
303+
)
304+
]
305+
)
280306
}
281307

282308
func testLikelySimulatorEnvironment() throws {

0 commit comments

Comments
 (0)