Side effects due to assignment are visible before the right hand side is evaluated #57484
Labels
bug
Indicates an unexpected problem or unintended behavior
compiler:lowering
Syntax lowering (compiler front end, 2nd stage)
Basic case
It's reasonable to expect
_, _ = ...
to evaluate the right hand side beforesetting the variables on the left. Some cases follow this intuition, for
example the swapping idiom:
Other cases, including those with a
ref
on the LHS, also work:However, others don't:
The lowering for
x, y = 2, x
:The lowering for
x, y = 2, f()
:Multiple
const
assignmentsIn 1.12 we have the related issue of constants becoming visible mid-evaluation
because of a
latestworld
. For example, inconst x, y = 2, f()
:Typeasserts
Typeasserts present yet another problem;
convert
can fail and leave only someof the variables assigned:
Lowered:
The text was updated successfully, but these errors were encountered: