@@ -287,13 +287,13 @@ export def kind(typeref: &TypeRef) -> TypeKind {
287287 }
288288}
289289
290- export def resolve(typeref: &TypeRef, scpe: &Scope) -> TypeId {
290+ export def resolve(typeref: &TypeRef, scpe: &Scope, error_on_fail: bool = true ) -> TypeId {
291291 if not typeref { return 0 }
292292 if typeref.tpe {
293293 return typeref.tpe
294294 }
295295 if typeref.name {
296- let id = scope::get_type_id(scpe, parser::make_identifier(typeref.name))
296+ let id = scope::get_type_id(scpe, parser::make_identifier(typeref.name), error_on_fail = error_on_fail )
297297 typeref.tpe = id
298298 return id
299299 }
@@ -2819,6 +2819,18 @@ export def replace_type_defs(
28192819 rtpe = left.value.tpe
28202820 }
28212821
2822+ if left.kw == parser::VarDecl::TYPE and rtpe and rtpe.kind == TypeKind::TYPE {
2823+ // We have a type parameter, create it in scope and continue
2824+ left.tpe = make_type_ref(rtpe)
2825+ scope::create_type(
2826+ scpe,
2827+ parser::make_identifier(left.name),
2828+ parser::ShareMarker::NONE,
2829+ make_type_ref(rtpe.tpe)
2830+ )
2831+ continue
2832+ }
2833+
28222834 if not rtpe { return }
28232835 if convert_type_score(left.tpe, rtpe, scpe, impl) < 0 { return }
28242836
@@ -2851,28 +2863,20 @@ export def replace_type_defs(
28512863 }
28522864}
28532865
2854- export def overload_score(
2855- a: FunctionDef, param_b: &Vector(NamedParameterPre), scpe: &scope::Scope,
2856- positional: bool, partial: bool = false, impl: bool = true) -> int {
2866+ export def parameter_equals(
2867+ a: FunctionDef, param_b: &Vector(NamedParameterPre), scpe: &scope::Scope) -> bool {
28572868
2858- // TODO Factor this out into a function and make sure that its used everywhere
2859- let param_b_converted = vector::make(NamedParameter)
2869+ if a.parameter_t.length != vector::length(param_b) {
2870+ return false
2871+ }
28602872 for var i in 0..vector::length(param_b) {
2861- let npb = param_b(i)
2862- param_b_converted.push([
2863- name = npb.name,
2864- tpe = npb.tpe.resolve(scpe),
2865- value = npb.value,
2866- kw = npb.kw,
2867- varargs = npb.varargs,
2868- node = npb.node
2869- ] !NamedParameter)
2873+ let left = param_b(i)
2874+ let right = a.parameter_t(i)
2875+ if left != right {
2876+ return false
2877+ }
28702878 }
2871-
2872- return overload_score(
2873- a.parameter_t, a.return_t, param_b_converted, scpe,
2874- positional, partial, impl
2875- )
2879+ return true
28762880}
28772881
28782882export def overload_score(
@@ -2948,11 +2952,11 @@ export def overload_score(
29482952 lvalue = array(left.tpe, parser::VarDecl::VAR)
29492953 }
29502954 var score = -1
2951- if lvalue and lvalue.kind() == TypeKind ::TYPE {
2955+ if left.kw == parser::VarDecl ::TYPE {
29522956 if kind(right.tpe) == TypeKind::TYPE {
29532957 if left.value and right.value and equals(left.value.value_tpe, right.value.value_tpe) {
29542958 score = 0
2955- } else if not left.value.value_tpe and right.value {
2959+ } else if not left.value and right.value {
29562960 // TODO test this
29572961 score = 4
29582962 }
@@ -3975,7 +3979,7 @@ def walk_Identifier(node: &parser::Node, state: &State) {
39753979 scope::add_reference(value, node)
39763980
39773981 if value.kind == scope::ValueKind::TYPE {
3978- node.tpe = _type(value.value.value_tpe )
3982+ node.tpe = _type(value.tpe.resolve(state.scope) )
39793983 } else {
39803984 node.tpe = value.get_type()
39813985 }
@@ -4280,7 +4284,12 @@ export def walk_VarDecl(node: &parser::Node, state: &State, set_constant: bool =
42804284 }
42814285
42824286 if tpe_node {
4283- ltypes.push(type_lookup(tpe_node, state).tpe)
4287+ let tpe = type_lookup(tpe_node, state)
4288+ if not tpe {
4289+ ltypes.push(0)
4290+ } else {
4291+ ltypes.push(tpe.tpe)
4292+ }
42844293 } else {
42854294 ltypes.push(0)
42864295 }
0 commit comments