Skip to content

ICE: inferred return joining a view return with a literal return (return x of &i32 beside return -1) #2325

Closed

Description

@ehartford

Spec: §9.1 / D43 (tail inference), D22 (a view materializes on an owned demand), §4.2.1.

Repro (main, installed compiler 2c8e014 era):

fn find(xs: &List[i32], want: i32):
    for x in xs:
        if x == want: return x
    return -1
fn main:
    let xs: List[i32] = [3, 7]
    print(f\"{find(&xs, 7)} {find(&xs, 9)}\")

Actual: internal compiler error: invalid MIR before codegen ... use rvalue type is incompatible with assign destination (dest ty=… kind=14, src … kind=1) in find.

The inferred return type joins &i32 (the view return) with the literal return; Sema then neither materializes return x to the owned value nor refuses the join, and MIR assigns an integer into a reference-typed return local.

Expected: the same answer as an if with mixed view and owned arms: the join is the owned value type (i32), return x materializes it, -1 is checked at i32. Returns are checked before the return type is inferred, so the view return needs its owned-demand adjustment recorded after inference (the d114-impl branch makes literal returns adapt to typed returns; the view case needs this).

Workaround: annotate -> i32.

Activity

  1. ehartford commented on Oct 23, 2026

    @ehartford
    ContributorAuthor

    Fixed on main (b050a01, PR #2587, stack #2588): one commit with the fixture test/behavior/behav_2325_inferred_return_from_view_loop.w, which failed before the fix and passes after; battery GREEN on the stack top 077d684 (669 s, pinned seed nightly-20261023-local-1).

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