Skip to content

A generic function used as a callable value has no type in Sema; invalid MIR (argument is Unit) #1857

Closed

Description

@ehartford

Spec

§12 callable values: a generic function named where a fn(i32) -> i32 is expected is instantiated at that type.

Repro

fn identity[T](x: T) -> T: x
fn apply(f: fn(i32) -> i32, x: i32) -> i32: f(x)
fn main:
    print(f"{apply(identity, 3)}")

Actual (main 355c20b)

with check: error only at MIR: invalid MIR before codegen: call argument 0 is Unit but the callee parameter is not. SemaCheck.check_ident returns 0 for a generic function name in value position (if self.generic_fn_node_for_symbol(sym) != 0 ...: return 0), so the argument has no type and no instantiation.

Expected

3 (instantiate identity[i32] from the expected callable type), or a Sema diagnostic naming the missing instantiation.

Workaround

Wrap it: apply((x) => identity(x), 3). Found while moving the callable-value fact to Sema (D65).

Activity

  1. ehartford commented on Oct 3, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by 792351b (stack #2007, battery green on 0f13a62). A generic function used as a callable value is instantiated at the expected fn type; with none it is a loud error.

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