Skip to content

Bare '(mut self)' receiver param passes check but collapses in lowering (codegen failure / bogus generic-contract BUG) #897

Closed

Description

@ehartford

Repro

use std.builtins.print_i32
type P { v: Vec[i32], n: i32 }
impl P:
    mut fn take_it(mut self):        // ← bare form, no `: Self`
        var x: Vec[i32] = move self.v
        print_i32(x.len() as i32)
fn main:
    var xs: Vec[i32] = Vec.new()
    xs.push(7)
    var p = P { v: xs, n: 1 }
    p.take_it()

with run → error: code generation failed (no diagnostic naming a site).
Variants of the same body produce BUG: user generic call lacks a concrete contract: ... sig=-1 mono=0 from MirModule.validate_generic_call_contracts
instead — including a move-free body (let x = self.v.clone(); x.len()), so
the collapse is the receiver form itself, not the field move.

Expected

Either the bare (mut self) spelling is legal and behaves exactly like the
two working forms, or it is a parse/sema error. Both canonical spellings work
today with the identical body:

  • mut fn take_it(): (implicit receiver) → OK
  • mut fn take_it(mut self: Self): (documented in InitTemplates) → OK

Evidence

  • analyze ... select: shows the bare form's receiver fact as
    declared=mut required=read even when the body vacates a field
    (write); the threading then lowers against the wrong mode.
  • Pre-existing: reproduces identically on the last-green seed; found while
    implementing D32 (the receiver-vacate fixtures), not introduced by it.
  • Also reproduces with (self) bare read receivers: sema errors
    "method receiver mode is missing; compiler effects require fn" — so the
    read-side bare form is at least loud; the mut-side bare form is silent
    until codegen.

Workaround used

D32 fixtures/migration use the implicit-receiver spelling. Fix should remove
the need to know this.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): still reproduces, now as an internal compiler error with the body named:

    impl P:
        mut fn take_it(mut self):
            var x: List[i32] = move self.v
    
    error: internal compiler error: invalid MIR before codegen (a bug in the With compiler, not in this program): use rvalue type is incompatible with assign destination (dest ty=196 kind=19, src ty=14 kind=4) in `take_it`
    

    pre-release: an ICE on a spelling the compiler accepts. Either the explicit receiver is refused beside mut fn (D7; eliminate-self.md phase 4), or it lowers like the synthesized one.

  2. ehartford commented on Oct 26, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by d8cd406 (#2718), merged through stack 8 whose seed-driven battery was green on its top (gate, uat and survey all green). Regression test: test/behavior/behav_897_written_receiver_is_the_keywords.w.

  3. added 2 commits that reference this issue on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions