You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A generator's mut parameter does not write through to the caller's value #3624
Found 2026-11-25 while building D216's mut poll (#2425). Reproduced on the installed compiler (main 745403b) and on a dev build of main 1fd6630.
type Box { n: i32 }
gen fn walk(mut b: Box) -> i32:
while b.n > 0:
b.n = b.n - 1
yield b.n
fn drain(mut b: Box):
while b.n > 0: b.n = b.n - 1
fn main:
var b = Box { n: 2 }
for x in walk(mut b): print(x)
print(b.n) // prints 2; expected 0
var c = Box { n: 2 }
drain(mut c)
print(c.n) // prints 0
The loop yields 1 and 0, so the generator mutates something, but not the caller's b: the generator's frame holds a copy. D172 (§3.8a): a mut p: T parameter is the caller's place. The program compiles with no diagnostic, so this is a silent wrong result.
Not yet root-caused: where a push generator's parameters are captured into its frame (D69) is the place to look.
Activity
D216: a contract states a polled tagged message; the program iterates…
A gen fn's mut parameter is the caller's place, held by the generator…