Skip to content

Commit a328c63

Browse files
committed
Rename IfConfigError -> IfConfigDiagnostic
1 parent 2bff318 commit a328c63

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

Sources/SwiftIfConfig/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ add_swift_syntax_library(SwiftIfConfig
1313
ConfiguredRegions.swift
1414
IfConfigRegionState.swift
1515
IfConfigDecl+IfConfig.swift
16-
IfConfigError.swift
16+
IfConfigDiagnostic.swift
1717
IfConfigEvaluation.swift
1818
IfConfigFunctions.swift
1919
SyntaxLiteralUtils.swift

Sources/SwiftIfConfig/IfConfigError.swift renamed to Sources/SwiftIfConfig/IfConfigDiagnostic.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ import SwiftDiagnostics
1414
import SwiftSyntax
1515
import SwiftSyntaxBuilder
1616

17-
/// Describes the kinds of errors that can occur when processing #if conditions.
18-
enum IfConfigError: Error, CustomStringConvertible {
17+
/// Describes the kinds of diagnostics that can occur when processing #if
18+
/// conditions. This is an Error-conforming type so we can throw errors when
19+
/// needed, but the cases themselves are a mix of warnings and errors when
20+
/// rendered as a diagnostic.
21+
enum IfConfigDiagnostic: Error, CustomStringConvertible {
1922
case unknownExpression(ExprSyntax)
2023
case unhandledFunction(name: String, syntax: ExprSyntax)
2124
case requiresUnlabeledArgument(name: String, role: String, syntax: ExprSyntax)
@@ -134,11 +137,11 @@ enum IfConfigError: Error, CustomStringConvertible {
134137
}
135138
}
136139

137-
extension IfConfigError: DiagnosticMessage {
140+
extension IfConfigDiagnostic: DiagnosticMessage {
138141
var message: String { description }
139142

140143
var diagnosticID: MessageID {
141-
.init(domain: "SwiftIfConfig", id: "IfConfigError")
144+
.init(domain: "SwiftIfConfig", id: "IfConfigDiagnostic")
142145
}
143146

144147
var severity: SwiftDiagnostics.DiagnosticSeverity {

Sources/SwiftIfConfig/IfConfigEvaluation.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func evaluateIfConfig(
4949
/// Record an if-config evaluation error before returning it. Use this for
5050
/// every 'throw' site in this evaluation.
5151
func recordError(
52-
_ error: IfConfigError
52+
_ error: IfConfigDiagnostic
5353
) -> (active: Bool, syntaxErrorsAllowed: Bool, diagnostics: [Diagnostic]) {
5454
return recordError(error, at: error.syntax)
5555
}
@@ -87,7 +87,7 @@ func evaluateIfConfig(
8787
active: result,
8888
syntaxErrorsAllowed: false,
8989
diagnostics: [
90-
IfConfigError.integerLiteralCondition(
90+
IfConfigDiagnostic.integerLiteralCondition(
9191
syntax: condition,
9292
replacement: result
9393
).asDiagnostic
@@ -234,7 +234,7 @@ func evaluateIfConfig(
234234
// The historical "macabi" environment has been renamed to "macCatalyst".
235235
if role == "environment" && arg == "macabi" {
236236
extraDiagnostics.append(
237-
IfConfigError.macabiIsMacCatalyst(syntax: argExpr)
237+
IfConfigDiagnostic.macabiIsMacCatalyst(syntax: argExpr)
238238
.asDiagnostic
239239
)
240240

@@ -335,7 +335,7 @@ func evaluateIfConfig(
335335
} else {
336336
// Complain about unknown endianness
337337
extraDiagnostics.append(
338-
IfConfigError.endiannessDoesNotMatch(syntax: argExpr, argument: arg)
338+
IfConfigDiagnostic.endiannessDoesNotMatch(syntax: argExpr, argument: arg)
339339
.asDiagnostic
340340
)
341341

@@ -466,7 +466,7 @@ func evaluateIfConfig(
466466

467467
// Warn that we did this.
468468
extraDiagnostics.append(
469-
IfConfigError.ignoredTrailingComponents(
469+
IfConfigDiagnostic.ignoredTrailingComponents(
470470
version: versionTuple,
471471
syntax: secondArg.expression
472472
).asDiagnostic
@@ -542,7 +542,7 @@ private func extractImportPath(_ expression: some ExprSyntaxProtocol) throws ->
542542
return [name]
543543
}
544544

545-
throw IfConfigError.expectedModuleName(syntax: ExprSyntax(expression))
545+
throw IfConfigDiagnostic.expectedModuleName(syntax: ExprSyntax(expression))
546546
}
547547

548548
/// Determine whether the given condition only involves disjunctions that
@@ -624,7 +624,7 @@ private func diagnoseLikelySimulatorEnvironmentTest(
624624
return nil
625625
}
626626

627-
return IfConfigError.likelySimulatorPlatform(syntax: ExprSyntax(binOp)).asDiagnostic
627+
return IfConfigDiagnostic.likelySimulatorPlatform(syntax: ExprSyntax(binOp)).asDiagnostic
628628
}
629629

630630
extension IfConfigClauseSyntax {
@@ -643,7 +643,7 @@ extension IfConfigClauseSyntax {
643643
{
644644

645645
foldingDiagnostics.append(
646-
IfConfigError.badInfixOperator(syntax: ExprSyntax(binOp)).asDiagnostic
646+
IfConfigDiagnostic.badInfixOperator(syntax: ExprSyntax(binOp)).asDiagnostic
647647
)
648648
return
649649
}

Sources/SwiftIfConfig/VersionTuple+Parsing.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension VersionTuple {
5858
func recordComponent(_ value: Int) throws {
5959
let limit = components.isEmpty ? 9223371 : 999
6060
if value < 0 || value > limit {
61-
throw IfConfigError.compilerVersionOutOfRange(value: value, upperLimit: limit, syntax: versionSyntax)
61+
throw IfConfigDiagnostic.compilerVersionOutOfRange(value: value, upperLimit: limit, syntax: versionSyntax)
6262
}
6363

6464
components.append(value)
@@ -68,14 +68,14 @@ extension VersionTuple {
6868
for (index, componentString) in componentStrings.enumerated() {
6969
// Check ahead of time for empty version components
7070
if componentString.isEmpty {
71-
throw IfConfigError.emptyVersionComponent(syntax: versionSyntax)
71+
throw IfConfigDiagnostic.emptyVersionComponent(syntax: versionSyntax)
7272
}
7373

7474
// The second component is always "*", and is never used for comparison.
7575
if index == 1 {
7676
if componentString != "*" {
7777
extraDiagnostics.append(
78-
IfConfigError.compilerVersionSecondComponentNotWildcard(syntax: versionSyntax).asDiagnostic
78+
IfConfigDiagnostic.compilerVersionSecondComponentNotWildcard(syntax: versionSyntax).asDiagnostic
7979
)
8080
}
8181
try recordComponent(0)
@@ -84,15 +84,15 @@ extension VersionTuple {
8484

8585
// Every other component must be an integer value.
8686
guard let component = Int(componentString) else {
87-
throw IfConfigError.invalidVersionOperand(name: "_compiler_version", syntax: versionSyntax)
87+
throw IfConfigDiagnostic.invalidVersionOperand(name: "_compiler_version", syntax: versionSyntax)
8888
}
8989

9090
try recordComponent(component)
9191
}
9292

9393
// Only allowed to specify up to 5 version components.
9494
if components.count > 5 {
95-
throw IfConfigError.compilerVersionTooManyComponents(syntax: versionSyntax)
95+
throw IfConfigDiagnostic.compilerVersionTooManyComponents(syntax: versionSyntax)
9696
}
9797

9898
// In the beginning, '_compiler_version(string-literal)' was designed for a

0 commit comments

Comments
 (0)