@@ -30,7 +30,8 @@ import SwiftSyntax
3030/// diagnose syntax errors in blocks where the check fails.
3131func evaluateIfConfig(
3232 condition: ExprSyntax ,
33- configuration: some BuildConfiguration
33+ configuration: some BuildConfiguration ,
34+ outermostCondition: Bool = true
3435) -> ( active: Bool , syntaxErrorsAllowed: Bool , diagnostics: [ Diagnostic ] ) {
3536 var extraDiagnostics : [ Diagnostic ] = [ ]
3637
@@ -111,7 +112,8 @@ func evaluateIfConfig(
111112 {
112113 let ( innerActive, innerSyntaxErrorsAllowed, innerDiagnostics) = evaluateIfConfig (
113114 condition: prefixOp. expression,
114- configuration: configuration
115+ configuration: configuration,
116+ outermostCondition: outermostCondition
115117 )
116118
117119 return ( active: !innerActive, syntaxErrorsAllowed: innerSyntaxErrorsAllowed, diagnostics: innerDiagnostics)
@@ -123,14 +125,17 @@ func evaluateIfConfig(
123125 ( op. operator. text == " && " || op. operator. text == " || " )
124126 {
125127 // Check whether this was likely to be a check for targetEnvironment(simulator).
126- if let targetEnvironmentDiag = diagnoseLikelySimulatorEnvironmentTest ( binOp) {
128+ if outermostCondition,
129+ let targetEnvironmentDiag = diagnoseLikelySimulatorEnvironmentTest ( binOp)
130+ {
127131 extraDiagnostics. append ( targetEnvironmentDiag)
128132 }
129133
130134 // Evaluate the left-hand side.
131135 let ( lhsActive, lhssyntaxErrorsAllowed, lhsDiagnostics) = evaluateIfConfig (
132136 condition: binOp. leftOperand,
133- configuration: configuration
137+ configuration: configuration,
138+ outermostCondition: false
134139 )
135140
136141 // Short-circuit evaluation if we know the answer and the left-hand side
@@ -157,7 +162,8 @@ func evaluateIfConfig(
157162 // Evaluate the right-hand side.
158163 let ( rhsActive, rhssyntaxErrorsAllowed, rhsDiagnostics) = evaluateIfConfig (
159164 condition: binOp. rightOperand,
160- configuration: configuration
165+ configuration: configuration,
166+ outermostCondition: false
161167 )
162168
163169 switch op. operator. text {
@@ -186,7 +192,8 @@ func evaluateIfConfig(
186192 {
187193 return evaluateIfConfig (
188194 condition: element. expression,
189- configuration: configuration
195+ configuration: configuration,
196+ outermostCondition: outermostCondition
190197 )
191198 }
192199
0 commit comments