@@ -44,8 +44,8 @@ export type TypeKind = enum {
4444 TYPE_CONSTRUCTOR
4545 // For patterns that are type instances
4646 TYPE_INSTANCE
47- // Forward declaration
48- // STUB
47+ // Type placeholder for types that haven't been compiled yet
48+ STUB
4949 // Placeholder for arguments with polymorphic type parameter in function definition
5050 TYPE_DEF
5151 // Reference to a type
@@ -335,6 +335,13 @@ export def kind(typeref: &TypeRef) -> TypeKind {
335335export def resolve(typeref: &TypeRef, scpe: &Scope, error_on_fail: bool = true) -> TypeId {
336336 if not typeref { return 0 }
337337 if typeref.tpe {
338+ let actual = typeref.tpe.resolve()
339+ if actual and actual.kind == TypeKind::STUB {
340+ // Lookup stub types on demand
341+ let id = scope::get_type_id(actual.defmodule.scope, parser::identifier_from_str(actual.type_name), error_on_fail)
342+ assert id == typeref.tpe
343+ return id
344+ }
338345 return typeref.tpe
339346 }
340347 if typeref.name {
@@ -570,7 +577,7 @@ export def equals(this: &Pattern, other: &Pattern, env: &EqEnv = null) -> bool {
570577 }
571578 }
572579 return true
573- case TypeKind::TUPLE, TypeKind::TUNION
580+ case TypeKind::TUPLE, TypeKind::TUNION, TypeKind::TYPE_INSTANCE
574581 if this.return_t.length() != other.return_t.length() {
575582 return false
576583 }
@@ -2532,9 +2539,9 @@ export def convert_type_score(a: &TypeRef, b: &Type, scpe: &scope::Scope, impl:
25322539 if not a or not b { return 0 }
25332540 if a.pattern {
25342541 return convert_type_score(a.pattern, b, scpe, impl)
2535- } /* else if a.name {
2542+ } else if a.name {
25362543 if scope::get_type(scpe, parser::identifier_from_str(a.name)) { return 1 }
2537- }*/ else {
2544+ } else {
25382545 return convert_type_score(a.resolve(scpe), b, scpe, impl)
25392546 }
25402547}
@@ -2977,12 +2984,17 @@ export def is_polymorph(tpe: &TypeRef) -> bool {
29772984 } else {
29782985 return is_polymorph(pattern.tpe)
29792986 }
2980- } else if pattern.kind == TypeKind::TUPLE or pattern.kind == TypeKind::TUNION {
2987+ } else if pattern.kind == TypeKind::TUPLE or
2988+ pattern.kind == TypeKind::TUNION or
2989+ pattern.kind == TypeKind::TYPE_INSTANCE {
2990+
29812991 for var tpe in pattern.return_t {
29822992 if is_polymorph(tpe) { return true }
29832993 }
29842994 return false
29852995 }
2996+ } else if tpe.name {
2997+ return true
29862998 }
29872999 return false
29883000}
@@ -5696,7 +5708,7 @@ export def walk_TypeDecl(node: &parser::Node, state: &State) {
56965708 type_value.defmodule = state.module
56975709
56985710 type_value.name = parser::identifier_to_str(name)
5699- print("Registered type ", type_value.name, " with id ", tpe, "\n")
5711+ // print("Registered type ", type_value.name, " with id ", tpe, "\n")
57005712 if value.kind != parser::NodeKind::TYPE_CONSTRUCTOR {
57015713 type_value.type_name = append_module(type_value.name, node.loc.module)
57025714 }
@@ -7499,14 +7511,14 @@ export def typecheck(state: &State) {
74997511 //lookup_stub_types(state)
75007512
75017513 // Typcheck Type decls
7502- for var i in 0..vector::length(node.body) {
7514+ /* for var i in 0..vector::length(node.body) {
75037515 let n = node.body(i)
75047516 switch n.kind !int {
75057517 case parser::NodeKind::TYPE_DECL
75067518 n.parent = node
75077519 walk_TypeDecl(n, state)
75087520 }
7509- }
7521+ }*/
75107522
75117523 typecheck(node, state)
75127524
0 commit comments