Skip to content

say(&o.unwrap_or(Vec.new())): MIR lowering fails — Vec.new() gets no expected type under & #1393

Closed

Description

@ehartford

Found during #1363.

fn ov() -> Option[Vec[i32]]: None
fn say(t: &Vec[i32]): print(t.len())
fn main:
    let o = ov()
    say(&o.unwrap_or(Vec.new()))

Actual (installed v0.15.2.1, origin/main 8c859a7): error: code generation failed; WITH_MIR_AUDIT=1 shows [mir-lower-fail] kind=27 fn=main at the Vec.new() span. The same default bound first (let v = o.unwrap_or(Vec.new())) compiles. Same for &(r ?? Vec.new()).

Expected: 0. The join (spec §3.8, §10) fixes the default arm type to Vec[i32]; the & operand context must not erase it.

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