Repository navigation
Fix item function chaining with whitespace before arrow operators - #12772
Conversation
|
Hello @@copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo. |
Add SinkWhitespace before checking for next arrow operator in chained transforms/functions to allow whitespace before subsequent arrows. Previously, whitespace before the second and subsequent arrows would cause parsing to fail. Added comprehensive tests to verify the fix works for various whitespace patterns. Co-authored-by: JanProvaznik <[email protected]>
JanProvaznik
left a comment
There was a problem hiding this comment.
@copilot good change though I have some feedback to ensure correctness:
Required Changes / Additional Tests
To approve this safely, I require the following test cases to be added to Expander_Tests.cs or ExpressionShredder_Tests.cs:
Trailing Whitespace:
code
C#
// Ensure this does not throw
expression = "@(I -> Count() )";
Quoted Transform Trailing Whitespace:
code
C#
// Ensure this does not throw
expression = "@(I -> 'Replacement' )";
Invalid Syntax after Whitespace (Regression check):
code
C#
// Should throw a clear syntax error, not crash or hang
expression = "@(I -> Count() invalid)";
Summary
The code change is likely correct, but insufficiently tested for "End of Expression" boundaries. Given the criticality of ExpressionShredder, we cannot assume the loop termination logic handles the new state without explicit proof.
Please add the trailing whitespace test cases before merging.
Added tests as requested by reviewer: - Trailing whitespace after function calls - Trailing whitespace after quoted transforms - Invalid syntax after whitespace to ensure proper error handling All tests pass successfully. Co-authored-by: JanProvaznik <[email protected]>
Added all requested test cases in commit ef43b74:
All 51 ExpressionShredder tests now pass, including the new edge case tests. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a parser bug where item function chaining failed when whitespace preceded the second or subsequent -> operator. The fix adds SinkWhitespace calls to consume trailing whitespace after processing each transform/function expression, before checking for the next -> operator.
- Adds whitespace consumption in two methods:
MoveNext()andGetReferencedItemNamesAndMetadata() - Provides comprehensive test coverage including edge cases for trailing whitespace
- Minimal change with only 4 lines of production code added
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Build/Evaluation/ExpressionShredder.cs | Added SinkWhitespace calls after processing quoted transforms and function expressions in both MoveNext() and GetReferencedItemNamesAndMetadata() methods to consume trailing whitespace before checking for the next -> operator |
| src/Build.UnitTests/Evaluation/ExpressionShredder_Tests.cs | Added comprehensive parser-level tests for chained functions with various whitespace patterns, trailing whitespace after functions/transforms, and invalid syntax validation |
| src/Build.UnitTests/Evaluation/Expander_Tests.cs | Added integration test that validates the fix by building a project with chained item functions containing whitespace before the second arrow operator |
Fixes #12713
Context
Item function chaining fails when whitespace precedes the second or subsequent
->operator:The parser in
ExpressionShredder.cschecks for->at loop start but doesn't consume trailing whitespace after processing each transform/function. WhencurrentIndexsits on whitespace after), theSinkcall looking for-fails.Changes Made
Added
SinkWhitespacecalls before loop continuation in two locations:MoveNext()method: After quoted transforms (line 187) and function expressions (line 202)GetReferencedItemNamesAndMetadata()method: After quoted transforms (line 341) and function expressions (line 348)This consumes trailing whitespace before checking for the next
->.Testing
ItemFunctionChainingWithWhitespaceBeforeArrowtest inExpander_Tests.csreproducing the exact issueExtractItemVectorExpressionsChainedFunctionsWithWhitespacetest inExpressionShredder_Tests.csvalidating parser behavior with various whitespace patternsExtractItemVectorExpressionsInvalidSyntaxAfterWhitespacetest to ensure invalid syntax after whitespace is properly rejected@(I -> Count() )) and quoted transforms (@(I -> 'Replacement' ))Notes
Four-line production code fix with comprehensive test coverage including edge cases. No breaking changes—existing whitespace-free syntax continues working.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.