Skip to content

Record update on larger structs can compile but produce incorrect runtime values #29

Closed

Description

@ehartford

Current behavior

Record update syntax on a larger struct compiles but produces the wrong value at runtime.

Minimal repro:

type LoopVars = {
v0: i32,
v1: i32,
v2: i32,
v3: i32,
v4: i32,
v5: i32,
v6: i32,
v7: i32,
}

fn set(vars: LoopVars, slot: i32, value: i32) -> LoopVars:
if slot == 0: return { vars with v0: value }
if slot == 1: return { vars with v1: value }
if slot == 2: return { vars with v2: value }
if slot == 3: return { vars with v3: value }
if slot == 4: return { vars with v4: value }
if slot == 5: return { vars with v5: value }
if slot == 6: return { vars with v6: value }
if slot == 7: return { vars with v7: value }
vars

fn main:
let vars = set(LoopVars {
v0: 0,
v1: 0,
v2: 0,
v3: 0,
v4: 0,
v5: 0,
v6: 0,
v7: 0,
}, 7, 9)
assert(vars.v7 == 9)

Observed behavior

with run exits with code 6 because the assertion fails.

Control case

A smaller record-update case works:

type Pair = { a: i32, b: i32 }
fn set_pair(p: Pair) -> Pair: { p with b: 9 }

Expected behavior

{ vars with v7: value } should produce a new record with only v7 changed.

Repro

cat > /tmp/record_update_large_struct_bug.w << 'EOF2'
type LoopVars = {
v0: i32,
v1: i32,
v2: i32,
v3: i32,
v4: i32,
v5: i32,
v6: i32,
v7: i32,
}

fn set(vars: LoopVars, slot: i32, value: i32) -> LoopVars:
if slot == 0: return { vars with v0: value }
if slot == 1: return { vars with v1: value }
if slot == 2: return { vars with v2: value }
if slot == 3: return { vars with v3: value }
if slot == 4: return { vars with v4: value }
if slot == 5: return { vars with v5: value }
if slot == 6: return { vars with v6: value }
if slot == 7: return { vars with v7: value }
vars

fn main:
let vars = set(LoopVars {
v0: 0,
v1: 0,
v2: 0,
v3: 0,
v4: 0,
v5: 0,
v6: 0,
v7: 0,
}, 7, 9)
assert(vars.v7 == 9)
EOF2
with run /tmp/record_update_large_struct_bug.w

Activity

  1. added
    bug
    error-messages
    on Mar 20, 2026
  2. added a commit that references this issue on Jun 8, 2026
    c73fd48
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

    bugerror-messages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions