Self referential types #8

Closed
opened 2026-06-15 15:01:50 +02:00 by st · 1 comment
Owner

Currently possible only in principle, compiler rejects it because recursive use of the types own name is not resolved

Repro

type IntList =
  | Nil 
  | Cons(i64, IntList)

fn len(l: IntList): i64 =
  match l with 
  | Nil -> 0 
  | Cons(h, t) -> Core.add_i64(1, len(t)) 
  end

fn main(): i64 = 
  len(Cons(1, Cons(2, Nil)))

Error: unknown type param: IntList (infer.ml:1992).

subst_ty assumes every TNamed in a variant payload is one of the enum's type parameters; a payload naming the enum itself isn't handled.

Currently possible only in principle, compiler rejects it because recursive use of the types own name is not resolved Repro ``` type IntList = | Nil | Cons(i64, IntList) fn len(l: IntList): i64 = match l with | Nil -> 0 | Cons(h, t) -> Core.add_i64(1, len(t)) end fn main(): i64 = len(Cons(1, Cons(2, Nil))) ``` Error: unknown type param: IntList (infer.ml:1992). subst_ty assumes every TNamed in a variant payload is one of the enum's type parameters; a payload naming the enum itself isn't handled.
Author
Owner

Fixed as of 8af56303f0

Fixed as of [8af56303f0](https://forge.haug.codes/st/amelie/commit/8af56303f0b2591a9b469b34631756dabf54acb9)
st 2026-06-15 19:24:28 +02:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
st/amelie#8
No description provided.