Skip to content

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

Closed

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.

Activity

  1. changed the title [-]Turbofish type args unsupported on free generic functions with value args[/-] [+]Free generic functions: uninferable type args need a restructure-hint diagnostic (turbofish not spec-promised)[/+] on Jul 2, 2026
  2. ehartford commented on Jul 2, 2026

    @ehartford
    ContributorAuthor

    Retitled per triage (provisional ruling, reversible if Eric wants the syntax): the spec does not promise turbofish/explicit type args on FREE functions — only method/type positions. Per the mission (no ceremony the compiler can avoid), the plan of record is: improve inference where possible, and where a type is genuinely uninferable, emit a diagnostic that says how to restructure (e.g. bind the result to an annotated type, or take the type from an argument). If Eric rules that explicit type args on free fns ARE wanted, this reverts to a spec-amendment + implementation issue.

  3. ehartford commented on Jul 2, 2026

    @ehartford
    ContributorAuthor

    Ruling confirmed (WWED, mission-derived): no turbofish on free functions. 'Every unnecessary character is a compiler failure' — the fix is inference plus a diagnostic that teaches the restructure (annotate the binding / take T from an argument). This issue stays as that diagnostic-work tracker. Revisit only with evidence that inference gaps are pervasive in real code.

  4. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Closed by the commit above, per the no-turbofish ruling: both failure modes now teach the restructure — turbofish attempts get 'explicit type arguments are not written at call sites; With infers them — annotate the result binding or let an argument carry the type', and uninferable type params get exactly one 'cannot infer type parameter T…' hint at the true source (ensure_generic_substitutions) with the old bare 'unknown type' cascade suppressed. Pinned by err_generic_fn_turbofish and err_generic_fn_uninferable. If field evidence later shows pervasive inference gaps, the syntax question can be reopened with data.

  5. added a commit that references this issue on Jul 4, 2026
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