Skip to content

Free generic functions: uninferable type args need a restructure-hint diagnostic (turbofish not spec-promised) #598

Description

@ehartford

Summary

Explicit type arguments (turbofish) on a free generic function with value arguments are not accepted: f[T](args) reports error: value is not callable. Only intrinsics (sizeof[T](), transmute[T](v), chan[T](cap)) and generic methods (recv.m[T](args)) support explicit type args; no-arg generic calls (g[T]()) also work. Return-type-driven inference does not fill the gap either (let x: S = ret_only(buf)error: unknown type 'T').

Repro

fn id[T](x: T) -> T: x
fn main:
    let a = id[i32](42)   // error: value is not callable

id(42) (inference) works; id[i32](42) does not.

Impact

Any free generic function whose T is not inferable from its value arguments (e.g. T appears only in the return type) is uncallable. This forced std.ffi (#436) to shape its recovery helpers as unbox_ctx[T](ctx: *mut T) (T carried by a cast argument) instead of the spec-natural unbox_ctx[State](ctx).

Root cause (where to look)

Sema.check_call (src/SemaCheck.w): a callee that is NK_INDEX over a plain NK_IDENT (the f[T] form) is only handled when the index base is a NK_FIELD_ACCESS (generic method / collect). For an ident base resolving to a generic free function, control falls through to the kind != NK_IDENT → "value is not callable" path (~line 11530). A branch that recognizes ident[TypeArgs](args) and binds the type args to the generic instantiation is missing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions