Repository navigation
Take the #else branch when every earlier condition is false - #71
Merged
Merged
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
What changed in this PR
Fixes conditional-compilation branch resolution so a reachable #else becomes the active branch when all earlier conditions are known-false, preventing false “unresolved #if” mutation errors for @Implicit declarations.
Changes:
- Treats
#elseclauses as active (true) once reached infilterInactiveIfConfig. - Adds test cases covering
@Implicitdeclarations inside an active#else(after#ifand after#elseif).
| File | Description |
|---|---|
| Sources/ImplicitsTool/CompilationConditionsConfig.swift | Adjusts clause-activity evaluation so #else can resolve as active. |
| Sources/TestResources/test_data/if_config_code_block.swift | Adds regression cases ensuring @Implicit declarations work in active #else branches. |
Review effort: Lite
Copilot stopped reviewing on behalf of
zienag due to an error
October 26, 2026 12:34
An #else clause has no condition, so evaluating it gave nil, the same as an unknown condition. With `#if FLAG ... #else ... #endif` and FLAG not defined, the #else was not recognized as the active branch: the whole #if stayed unresolved, and an @implicit declaration in #else failed with "Cannot mutate implicit context inside '#if' block with unresolved condition", noted at the known condition. Reads in such a block still worked, so the existing filtering tests missed it. A clause is now recognized as #else by its keyword and counts as true once reached. parsedCondition uses the same check instead of inferring #else from a missing condition.
zienag
force-pushed
the
active-else-clause
branch
from
October 26, 2026 13:35
bbace31 to
47a9c22
Compare
zienag
enabled auto-merge (squash)
October 26, 2026 13:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



With known compilation conditions, an
#elsereached after false conditions was not treated as the active branch. An#elseclause has no condition, and evaluating it gavenil, the same as an unknown condition, so the whole#ifstayed unresolved. Reads inside it still worked, but an@Implicitdeclaration in the#elsefailed with "Cannot mutate implicit context inside '#if' block with unresolved condition", and the note pointed at a condition that was in fact known. A release build hit this with#if INTERNAL_BUILD ... #else @Implicit() var voiceDialog: VoiceDialog = io #endifwhenINTERNAL_BUILDwas not defined.Changes
filterInactiveIfConfigrecognizes an#elseby its keyword and counts it as true once reached. An#elseafter an unknown condition still stays unresolved, as before.parsedConditionuses the sameisElsecheck instead of inferring#elsefrom a missing condition.if_config_code_block.swiftcovers declarations in an active#elseafter a false#ifand#elseif.Test plan
#if Dand#elseif Elines.swift test(Xcode Swift 6.3.2): 121 tests pass.