🐛 fix(mq-check): propagate piped input to function calls inside let bindings#1461
Merged
🐛 fix(mq-check): propagate piped input to function calls inside let bindings#1461
Conversation
…indings When `items | let x = first()` was used, the piped value was not passed to `first()` as its implicit first argument, causing false type errors. Three-part fix: - Add Pass 2.7 in constraint generation to forward root-level Variable piped inputs to their initializer Call/Ref before Pass 3 runs - Extend `might_receive_piped_input` to defer errors for Calls inside Variables that are children of Block/Function/Macro - Add `propagate_piped_input_to_variable_initializer` in pipe.rs to re-process Call initializers in Block-level Variables during Pass 4
…iteration Eliminates a second O(R) scan over root_symbols and removes one `get_piped_input` HashMap lookup per root-level Variable by propagating piped input to Variable initializers within the existing Pass 2 loop.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the mq-check type checker where piped input was not propagated to function calls inside let bindings. For example, [1, 2, 3] | let x = first() | x would incorrectly produce type errors because first() didn't see the piped array as its implicit argument.
Changes:
- Added
propagate_piped_input_to_variable_initializerto forward piped types fromVariablenodes to their initializerCall/Refexpressions in pipe chains. - Extended
might_receive_piped_inputto recognize calls nested insideVariablenodes within pipe-capable constructs, preventing premature error reporting. - Added integration tests for let bindings with piped function calls (
first,last,length,upcase).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
crates/mq-check/src/constraint.rs |
Pass 2 now also propagates piped input into Variable initializers for root-level pipe chains. |
crates/mq-check/src/constraint/pipe.rs |
Refactored pipe-chain processing to handle SymbolKind::Variable via a new propagate_piped_input_to_variable_initializer function. |
crates/mq-check/src/constraint/helpers.rs |
Extended might_receive_piped_input to handle grandparent check for Variable parents. |
crates/mq-check/tests/integration_test.rs |
Added parameterized tests for let bindings with piped function calls. |
| { | ||
| let init_children = get_children(&children_index, cats.root_symbols[i]); | ||
| if let Some(&init_id) = init_children.last() { | ||
| ctx.set_piped_input(init_id, prev_ty); |
…length()' for piped array in let binding
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.
No description provided.