You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Free generic functions: uninferable type args need a restructure-hint diagnostic (turbofish not spec-promised) #598
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.
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
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.
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.
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.
Activity
[-]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)[/+]ehartford commentedon Jul 2, 2026
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.
ehartford commentedon Jul 2, 2026
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.
ehartford commentedon Jul 3, 2026
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.
Teaching diagnostics for free-generic-fn type args (#598, ruled: no t…
Diagnostics: a failed generic bound stops the instantiation; build wa…
Type checker: D74 entry sources and chain moves, field-view bindings (#…
D100: a field without pub is private to its package (#2209) (#2212)