/// Regression test: `undefined` fields in record literals must not
/// produce phantom SSA blits.
///
/// Previously, `{ paramTypes: undefined, ... }` emitted a `reserve`
/// for the field and then a `blit` from that reserve - but the source
/// register was never defined, creating a phantom SSA value that the
/// backend could not handle.
///
/// The fix skips stores for `undefined` fields entirely, leaving the
/// memory uninitialised.  Covers both named-field syntax (lowerRecordFields)
/// and positional constructor syntax (lowerRecordCtor).

record Small: Copy {
    x: i32,
    y: i32,
}

record WithArray: Copy {
    data: [i32; 4],
    len: i32,
}

/// Construct a record with one field `undefined` (named-field syntax).
/// The IL must not contain a `blit` or `store` for `x`.
fn partialInit() -> i32 {
    let s = Small { x: undefined, y: 42 };
    return s.y;
}

/// Construct a record with an array field `undefined` (named-field syntax).
/// The IL must not contain a `blit` for `data`.
fn arrayFieldUndef() -> i32 {
    let w = WithArray { data: undefined, len: 3 };
    return w.len;
}

/// Both fields defined - normal case for comparison.
fn fullInit() -> i32 {
    let s = Small { x: 10, y: 20 };
    return s.x + s.y;
}

union Tagged: Copy {
    A { data: [i32; 4], tag: i32 },
    B,
}

/// Union variant with record payload containing an `undefined` field.
/// This exercises `lowerRecordCtor` (positional constructor path).
fn unionPayloadUndef() -> i32 {
    let t = Tagged::A { data: undefined, tag: 99 };
    match t {
        case Tagged::A { tag, .. } => return tag,
        else => return -1,
    }
}
