Skip to content

A narrower integer auto-referenced at a user &i64 parameter is read in place: -1 arrives as 4294967295 #2336

Closed

Description

@ehartford

Spec: §4.2.6 (an integer widens into a wider type "on every container argument, as it does at a let or a call"), §3.8 (auto-referencing).

Repro (installed compiler on main, and D114 stage1):

fn f(x: &i64) -> i64: *x
fn main:
    let a: i32 = -1
    let b: i32 = -2
    print(f(a))
    print(f(b))

Expected: -1 and -2. The argument widens to i64, which must be materialized as an i64 temporary for the &i64 to view.

Actual:

4294967295
4294967294

The call passes the address of the four-byte i32 place and the callee reads eight bytes.

The std containers already do this correctly: test/behavior/behav_container_arg_widening.w (v64.contains(u) with u: u32, k.get(u) over HashMap[i64, i64]) widens through the container intrinsics in codegen. A user function's &T parameter takes the plain auto-reference path instead.

Fix direction: Sema records the widening conversion on an auto-referenced argument (as it records a contextual copy), and MIR materializes a temporary of the pointee type and passes its address. Refusing the call instead would contradict §4.2.6 and the container test.

Found during the D114 corpus run (#2327). D114 makes the case common because a literal list is a List[isize].

Activity

  1. ehartford commented on Oct 11, 2026

    @ehartford
    ContributorAuthor

    Fixed on branch d115-d120 (commit b8ce24c): can_auto_ref_arg_frozen accepts the widening types_compatible accepts for a numeric pointee, so the argument takes the auto-reference path, and lower_auto_ref_call_arg materializes a temporary of the pointee's type and views that. Before, the call went by value (call f(copy _1) with _1: i32 against &i64). Fixture: test/behavior/behav_2336_autoref_widening.w.

  2. added a commit that references this issue on Oct 11, 2026
  3. ehartford commented on Oct 11, 2026

    @ehartford
    ContributorAuthor

    Merged to main in e4861e1 (#2349), battery green.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions