@@ -30,7 +30,8 @@ import SwiftSyntax
30
30
/// diagnose syntax errors in blocks where the check fails.
31
31
func evaluateIfConfig(
32
32
condition: ExprSyntax ,
33
- configuration: some BuildConfiguration
33
+ configuration: some BuildConfiguration ,
34
+ outermostCondition: Bool = true
34
35
) -> ( active: Bool , syntaxErrorsAllowed: Bool , diagnostics: [ Diagnostic ] ) {
35
36
var extraDiagnostics : [ Diagnostic ] = [ ]
36
37
@@ -111,7 +112,8 @@ func evaluateIfConfig(
111
112
{
112
113
let ( innerActive, innerSyntaxErrorsAllowed, innerDiagnostics) = evaluateIfConfig (
113
114
condition: prefixOp. expression,
114
- configuration: configuration
115
+ configuration: configuration,
116
+ outermostCondition: outermostCondition
115
117
)
116
118
117
119
return ( active: !innerActive, syntaxErrorsAllowed: innerSyntaxErrorsAllowed, diagnostics: innerDiagnostics)
@@ -123,14 +125,17 @@ func evaluateIfConfig(
123
125
( op. operator. text == " && " || op. operator. text == " || " )
124
126
{
125
127
// 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
+ {
127
131
extraDiagnostics. append ( targetEnvironmentDiag)
128
132
}
129
133
130
134
// Evaluate the left-hand side.
131
135
let ( lhsActive, lhssyntaxErrorsAllowed, lhsDiagnostics) = evaluateIfConfig (
132
136
condition: binOp. leftOperand,
133
- configuration: configuration
137
+ configuration: configuration,
138
+ outermostCondition: false
134
139
)
135
140
136
141
// Short-circuit evaluation if we know the answer and the left-hand side
@@ -157,7 +162,8 @@ func evaluateIfConfig(
157
162
// Evaluate the right-hand side.
158
163
let ( rhsActive, rhssyntaxErrorsAllowed, rhsDiagnostics) = evaluateIfConfig (
159
164
condition: binOp. rightOperand,
160
- configuration: configuration
165
+ configuration: configuration,
166
+ outermostCondition: false
161
167
)
162
168
163
169
switch op. operator. text {
@@ -186,7 +192,8 @@ func evaluateIfConfig(
186
192
{
187
193
return evaluateIfConfig (
188
194
condition: element. expression,
189
- configuration: configuration
195
+ configuration: configuration,
196
+ outermostCondition: outermostCondition
190
197
)
191
198
}
192
199
0 commit comments