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
Sema: a generic type declared after the type that uses it is 'unknown type' #1440
A generic type declared after a non-generic type that uses it is rejected by Sema with unknown type. Declaration order must not matter (it does not for non-generic types).
type Holder { g: Gen[i32] }
fn main:
let h = Holder { g: Gen { t: 5 } }
print(f"{h.g.t}")
type Gen[T] { t: T }
error: unknown type: Gen
--> c1.w:1:18
1 | type Holder { g: Gen[i32] }
Same for a generic enum (enum Holder: H(g: Gen[Inner]) | N above enum Gen[T]: Of(t: T) | Nothing). Moving Gen above Holder compiles and runs.
Where
src/Sema.w ~4239-4262 (resolve_type_expr, TY_GENERIC_INST branch): lookup_named_type_visible(gi_base_sym) misses because the generic template is not registered yet when the earlier declaration's field types are resolved, and type_decl_nodes does not contain it either, so the path ends in emit_error("unknown type: " ...). Generic templates need to be registered (or resolution deferred) before any declaration's member types are resolved.
Found while fixing #1430 (the #1430 fixtures declare their generic templates first for this reason).
Activity
Sema: a generic type declared after the declaration that uses it reso…
Sema: a generic type declared after the declaration that uses it reso…
ehartford commentedon Sep 26, 2026
Verified fixed on main 55739d4 (release binary): Gen[T] declared after Holder prints 5.