Skip to content

projected intrinsic receiver lowering mutates temporaries instead of storage #78

Closed

Description

@ehartford

Summary

Projected intrinsic receiver lowering does not preserve lvalue identity. When an intrinsic receiver is a projection rooted in a non-place expression, MIR materializes the base into a temporary and the mutation lands on that temporary instead of the underlying storage.

This issue now tracks only the projected-receiver MIR bug. Collection-specific follow-ups were split into separate issues.

Spec references:

  • docs/with-specification.md §3.7 Auto-Dereferencing
  • docs/with-specification.md §3.8 Auto-Referencing
  • docs/with-specification.md §7.7 method call syntax for self: &T / self: &mut T

Minimal repro

type Inner { tags: Vec[i32] }

fn do_push(items: &mut Vec[Inner]):
    let item = items.get(0)
    item.tags.push(99)

fn main:
    var inners: Vec[Inner] = Vec.new()
    inners.push(Inner { tags: Vec.new() })
    do_push(&mut inners)
    assert(inners.get(0).tags.len() == 1)
    assert(inners.get(0).tags.get(0) == 99)

Expected

Mutating through a projected receiver should update the underlying storage regardless of whether the receiver expression is written directly, grouped, aliased, or returned from a helper.

Actual

The mutation is applied to a temporary copy of the projected value, so the original storage is unchanged and the runtime assertions fail.

Root cause

In src/MirLower.w, lower_intrinsic_call lowers instance receivers via lower_expr(self_expr). For field access, lower_expr turns the field place into OK_COPY, and lower_expr_place materializes non-place bases into temporaries. For shapes like items.get(0).tags.push(...), the get(0) result becomes a temporary local and push mutates temp.tags instead of the vec element.

Affected tests

  • test/behavior/issue64_mut_vec_get_method_chain.w
  • test/behavior/issue64_imported_projection_intrinsic_chain.w
  • test/behavior/issue64_receiver_shape_matrix.w

Activity

  1. added
    bug
    on Apr 6, 2026
  2. changed the title [-]receiver-shape lowering regresses projected mutations and borrowed collection methods[/-] [+]projected intrinsic receiver lowering mutates temporaries instead of storage[/+] on Apr 6, 2026
  3. ehartford commented on Apr 6, 2026

    @ehartford
    ContributorAuthor

    Split follow-ups out of this issue after investigation:

    This issue now tracks only the projected-receiver MIR lvalue-preservation bug.

  4. ehartford commented on Apr 7, 2026

    @ehartford
    ContributorAuthor

    Closed by a1225df (Fix #78 bound Vec.get receiver alias lowering). Root cause was MIR lowering forcing let item = items.get(0) into an owning local copy instead of preserving the vec element place, so item.tags.push(...) mutated the copied Inner. Validation: make build, make selfcheck, make fixpoint, targeted issue64 repros, and make test now at 537 passed / 1 failed with only #77 remaining.

  5. added a commit that references this issue on Jun 8, 2026
    5331b2e
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