Skip to content

validate-ownership: generator next body drops a local on a resume path that never initialized it #1412

Closed

Description

@ehartford

Found while sweeping --validate-all for #1394 (origin/main dd786a4 + the #1394 validator commit, which does not change this check).

examples/nebula/src/main.w     ownership MIR: fn sym1193 stmt17 span=0: drop of _9 reaches a path that never initialized it (Uninit)
examples/nebula/src/session.w  ownership MIR: fn sym1133 stmt17 span=0: drop of _9 reaches a path that never initialized it (Uninit)

sym1193 is __with_generator_next_884. Its entry switches on __with_generator_resume to bb1 (fresh start) or bb11 (resume after a yield); _9 (a str call result inside the loop body) is initialized only on the fresh path, and the resume path reaches its drop. Either the generator state machine must carry _9 across the yield (it is live) or the resume path must not drop it. Check at runtime with run --debug-alloc on a generator whose yielded expression builds a str.

Activity

  1. ehartford commented on Sep 23, 2026

    @ehartford
    ContributorAuthor

    It is wrong code at run time, not only a validator verdict. Stage2 of main f1e3bd2 (and the installed v0.15.2.1):

    type Telemetry { device_id: str, temp: f64 }
    
    gen fn extract_packets(count: i32) -> Telemetry:
        for i in 0..count:
            yield Telemetry {
                device_id: f"dev-{i}",
                temp: 20.0 + (i as f64) * 0.5,
            }
    
    fn main:
        var n = 0
        for p in extract_packets(3):
            n = n + p.device_id.len() as i32
        print(f"{n}")
    

    Expected 15; every compiler prints panic: integer overflow: i32 addition out of range — the consumer reads a garbage len(). check --validate-all: fn sym993 stmt16 span=0: drop of _9 reaches a path that never initialized it (Uninit).

    (Found again while sweeping for #1411: nebula's two files failed earlier at #1411's "terminator place has no concrete MIR type", which masked this.)

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions