Skip to content

Uninferable-but-mentioned generic type param silently defaults to i32, producing phantom 'expects &i32' diagnostics #738

Closed

Description

@ehartford

SemaDecl.w:2792 (ensure_generic_substitutions): when a type parameter is unbound after argument inference but IS mentioned in some parameter's type, Sema silently substitutes i32:

if self.type_param_mentions_any_param_type(tp_name, param_start, param_count) != 0:
    self.put_generic_subst(tp_name, self.ty_i32, call_node)

Downstream this manufactures diagnostics about types the user never wrote — #737's original report showed argument 1 expects &i32 for a param declared &C (the binder failed to bind C, then C silently became i32). The binder gap is fixed under #737, but every remaining inference gap that leaves a mentioned param unbound (e.g. a mismatched generic base: fn f[T](x: SomeStruct[T]) called with a different container) still reaches this default and reports i32-flavored nonsense instead of the honest #598 teaching diagnostic ('cannot infer type parameter ...').

This is a silent fallback (CLAUDE.md forbids these): translation failed, output fabricated. Wants: emit the #598 diagnostic in the mentioned case too (or thread the real reason binding failed). Needs care: the default may be load-bearing for error-recovery cascades where arg types are already 0 — audit callers before removing.

Activity

  1. ehartford commented on Jul 28, 2026

    @ehartford
    ContributorAuthor

    Fixed in c7dc28c (battery green; seed + installed now v0.15.1-gc7dc28ce).

    On a clean compile, a mentioned-but-unbound type parameter now reports the inference failure by name — 'cannot infer type parameter T for this call; the argument's shape does not match the parameter type that mentions T' — instead of silently substituting i32 and letting downstream diagnostics blame types the user never wrote. The i32 default survives only as cascade suppression when the call's arguments already errored (single-error output preserved for broken call sites, verified). Pinned by test/compile_errors/err_generic_uninferable_mentioned_param.w.

  2. added 3 commits that reference this issue on Aug 9, 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