v3: lower value-context match/if block operands with !/? propagation (fix #28000) - #28011
Open
medvednikov wants to merge 37 commits into
Open
v3: lower value-context match/if block operands with !/? propagation (fix #28000)#28011medvednikov wants to merge 37 commits into
!/? propagation (fix #28000)#28011medvednikov wants to merge 37 commits into
Conversation
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.
Fix #28000 (v3 backend)
This is the v3-only portion of #28002, split out per request (the
vlib/vcompiler changes from that PR are dropped here). #28002 is being closed in favor of this.A
match/ifused as the value of another expression — a cast, a string-interpolation part,dump(), a prefix/infix operand, an index expression, a selector receiver, or anasoperand — must have its (possibly propagating,!/?) branch tails lowered as values. Previously the v3 transformer lowered them in a value-less statement context, which produced an empty ternary / expression for the propagated result.Change
vlib/v3/transform/transform.v: addtransform_value_operandandis_value_match_or_if_operandhelpers. The latter looks through transparent wrappers —(...)parens,unsafe { }blocks, and a trailingexpr_stmt(including compositions likei64(unsafe { match ... })). Route the affected operands (string-interp parts,dump(), infix/prefix operands, index children, selector base, cast operands, and block-expr value tails) through target-typed lowering.vlib/v3/transform/sum.v: handle amatch/ifoperand of anascast by materializing it into a value temp first, then re-running theasconversion.Test
vlib/v3/tests/match_as_if_expr_value_propagation_codegen_test.v— covers!/?propagation for amatchused as an if-guard value, and wrapped in parens /unsafe/ cast / interpolation / dump / prefix / index / selector operands.Reproduction from the issue now compiles and runs correctly: