Skip to content

Commit 73cfd08

Browse files
committed
Expand IfConfigRegionState.evaluate() result to include syntaxErrorsAllowed
The compiler needs this information, and other clients probably will, too.
1 parent dad947a commit 73cfd08

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Sources/SwiftIfConfig/IfConfigRegionState.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public enum IfConfigRegionState {
2525
case active
2626

2727
/// Evaluate the given `#if` condition using the given build configuration
28-
/// to determine its state and identify any problems encountered along the
29-
/// way.
28+
/// to determine its state, whether syntax errors in inactive conditions are
29+
/// permitted, and to identify any problems encountered along the way.
3030
public static func evaluating(
3131
_ condition: some ExprSyntaxProtocol,
3232
in configuration: some BuildConfiguration
33-
) -> (state: IfConfigRegionState, diagnostics: [Diagnostic]) {
33+
) -> (state: IfConfigRegionState, syntaxErrorsAllowed: Bool, diagnostics: [Diagnostic]) {
3434
// Apply operator folding for !/&&/||.
3535
var foldingDiagnostics: [Diagnostic] = []
3636
let foldedCondition = OperatorTable.logicalOperators.foldAll(condition) { error in
@@ -44,9 +44,9 @@ public enum IfConfigRegionState {
4444

4545
let diagnostics = foldingDiagnostics + evalDiagnostics
4646
switch (active, syntaxErrorsAllowed) {
47-
case (true, _): return (.active, diagnostics)
48-
case (false, false): return (.inactive, diagnostics)
49-
case (false, true): return (.unparsed, diagnostics)
47+
case (true, _): return (.active, syntaxErrorsAllowed, diagnostics)
48+
case (false, false): return (.inactive, syntaxErrorsAllowed, diagnostics)
49+
case (false, true): return (.unparsed, syntaxErrorsAllowed, diagnostics)
5050
}
5151
}
5252
}

Tests/SwiftIfConfigTest/EvaluateTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ fileprivate func assertIfConfig(
269269
// Evaluate the condition to check the state.
270270
let actualDiagnostics: [Diagnostic]
271271
let actualState: IfConfigRegionState
272-
(actualState, actualDiagnostics) = IfConfigRegionState.evaluating(condition, in: configuration)
272+
(actualState, _, actualDiagnostics) = IfConfigRegionState.evaluating(condition, in: configuration)
273273
XCTAssertEqual(actualState, expectedState, file: file, line: line)
274274

275275
// Check the diagnostics.

0 commit comments

Comments
 (0)