Skip to content

A generator's mut parameter does not write through to the caller's value #3624

Done

Description

@ehartford

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

  1. added
    bug
    on Nov 26, 2026
  2. added a commit that references this issue on Nov 28, 2026
    a4cf71f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions