Fix chained item function empty result comparison in conditions#12901
Merged
JanProvaznik merged 4 commits intodotnet:mainfrom Feb 2, 2026
Merged
Conversation
The issue is that when chaining item functions like:
@(TestItem->WithMetadataValue('Identity', 'Test1')->WithMetadataValue('Foo', 'Baz'))
The result incorrectly evaluates as non-empty when compared in a condition, even though the actual result is empty.
Initial hypothesis was that the BreakOnNotEmpty optimization in Transform() was breaking early after the first transform. However, testing revealed that the Transform() method is NOT being called at all for chained transforms with BreakOnNotEmpty option.
This suggests the bug is elsewhere - possibly in how ExpressionShredder parses chained transforms or in how they're evaluated separately.
Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
When chaining item functions like @(Item->Func1()->Func2()), and the final result is empty, the condition comparison with empty string was incorrectly evaluating to false. The bug was in the Transform method in Expander.cs. The original code checked for BreakOnNotEmpty after EACH intermediate transform, causing it to break early when an intermediate result was non-empty, even if subsequent transforms would filter to an empty result. The fix moves the BreakOnNotEmpty check to after ALL transforms in the chain complete, ensuring we only check the final result, not intermediate ones. Added a unit test to verify the fix works correctly. Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug (#12877) where chained item functions incorrectly evaluated as non-empty in conditions when the final result was actually empty. The issue occurred because the BreakOnNotEmpty optimization was checking intermediate results after each transform in the chain, rather than checking only the final result after all transforms completed.
Key changes:
- Modified the
Transformmethod inExpander.csto delay theBreakOnNotEmptycheck until after all chained transforms complete - Added a test case to verify chained item functions with empty results are correctly evaluated in conditions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Build/Evaluation/Expander.cs | Moved BreakOnNotEmpty optimization check from inside the transform loop to after all transforms complete, ensuring correct evaluation of chained item functions |
| src/Build.UnitTests/Evaluation/Expander_Tests.cs | Added test case ChainedItemFunctionEmptyResultInCondition to verify the bug fix with a scenario using chained WithMetadataValue functions |
YuliiaKovalova
approved these changes
Feb 2, 2026
Copilot AI
added a commit
that referenced
this pull request
Feb 3, 2026
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
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.
Fixes #12877
Context
Chained item functions incorrectly evaluate as non-empty in conditions when the final result is empty. For example:
The first transform matches
Test1, but the second filters it out (Foo="Bar"!="Baz"). The final result is empty, yet the condition fails.Changes Made
src/Build/Evaluation/Expander.cs
BreakOnNotEmptycheck inTransformmethod to execute after all chained transforms complete, not after each intermediate transformsrc/Build.UnitTests/Evaluation/Expander_Tests.cs
ChainedItemFunctionEmptyResultInConditiontest verifying the fixTesting
Notes
BreakOnNotEmptyoptimization (condition evaluation path), not in normal property expansion.