@@ -469,17 +469,17 @@ def find_functions(value: &Value, resolved: &SMap(&Vector(typechecking::Function
469469def find_functions(scope: &Scope, name: Str, ret: &Vector(&Value), params: &Vector(typechecking::TypeId) = null, check_export: bool = false) {
470470 for var key in @scope.fields.keys() {
471471 var value = scope.fields(key)
472- let value_tpe = value.tpe.resolve()
473- if key == name and value.modifier == parser::VarDecl::CONST and value.kind == ValueKind::FUNCTION {
472+ if key == name and value.kind == ValueKind::FUNCTION {
473+ let value_def = value.fdef
474474 while value {
475475 if params {
476- if value_tpe .parameter_t.length < params.length {
476+ if value_def.sig .parameter_t.length < params.length {
477477 continue
478478 }
479479 var parameter_mismatch = false
480480 for var i in 0..params.length {
481481 let param = params(i)
482- if not typechecking::is_assignable(value_tpe .parameter_t(i).tpe, param, scope.module) {
482+ if not typechecking::is_assignable(value_def.sig .parameter_t(i).tpe, param, scope.module) {
483483 parameter_mismatch = true
484484 break
485485 }
@@ -531,14 +531,13 @@ def find_functions(scope: &Scope, tpe: &typechecking::Type, ret: &Vector(&Value)
531531 for var key in @scope.fields.keys() {
532532 var value = scope.fields(key)
533533 if check_export and not (value.share !int & parser::ShareMarker::EXPORT !int) { continue }
534- let value_tpe = value.tpe.resolve()
535- if value.modifier == parser::VarDecl::CONST and value_tpe and
536- value_tpe.kind == typechecking::TypeKind::FUNCTION {
534+ if value.kind == ValueKind::FUNCTION {
535+ let value_def = value.fdef
537536 while value {
538- if value_tpe .parameter_t.length > 0 and
539- typechecking::is_assignable(value_tpe .parameter_t(0).tpe, tpe, scope.module) {
540- if not set::contains(found, value_tpe.type_name ) {
541- set::add(found, value_tpe.type_name )
537+ if value_def.sig .parameter_t.length > 0 and
538+ typechecking::is_assignable(value_def.sig .parameter_t(0).tpe, tpe, scope.module) {
539+ if not set::contains(found, value_def.name ) {
540+ set::add(found, value_def.name )
542541 ret.push(value)
543542 }
544543 }
@@ -763,10 +762,11 @@ export def find_implicit_function(scope: &Scope, parameter_t: &Vector(typechecki
763762 /*if v.node and v.state {
764763 v.tpe = typechecking::lookup_parameters(v.node, v.state)
765764 }*/
766- let vtpe = v.tpe.resolve()
765+ assert v.kind == ValueKind::FUNCTION
766+ let fdef = v.fdef
767767
768- if not typechecking::equals(vtpe .return_t(0), r) { continue }
769- let s = typechecking::convert_type_score(vtpe .parameter_t(0).get_generic(), parameter_t(0).tpe, context.module, impl = false)
768+ if not typechecking::equals(fdef.sig .return_t(0), r) { continue }
769+ let s = typechecking::convert_type_score(fdef.sig .parameter_t(0).get_generic(), parameter_t(0).tpe, context.module, impl = false)
770770 if s == @score {
771771 d = true
772772 } else if s >= 0 and s < @score {
@@ -814,9 +814,9 @@ export def find_implicit_function(scope: &Scope, parameter_t: &Vector(typechecki
814814
815815 if value and value.phase == Phase::DEFINED and value.node and force_compile {
816816 // TODO Factor this out
817- assert is_function( value.tpe)
818- let fun_tpe = value.tpe.resolve()
819- if typechecking::is_polymorph(fun_tpe .parameter_t) {
817+ assert value.kind == ValueKind::FUNCTION
818+ let fdef = value.fdef
819+ if typechecking::is_polymorph(fdef.sig .parameter_t) {
820820 typechecking::walk_Def_with_type_argument(value.node, parameter_t, scope, typechecking::make_state(value.module))
821821 } else {
822822 let state = typechecking::make_state(value.module)
@@ -1061,9 +1061,10 @@ export def create_underscore(scope: &Scope, name_node: &parser::Node, tpe: typec
10611061}
10621062
10631063export def typecheck_function(value: &Value, parameter_t: &Vector(typechecking::NamedParameter), context: &Scope) -> &Value {
1064+ assert value.kind == ValueKind::FUNCTION
10641065 value.phase = Phase::COMPILED
10651066 //let tpe = typechecking::lookup_parameters(value.node, value.state)
1066- if typechecking::is_polymorph(value.tpe.resolve() .parameter_t) {
1067+ if typechecking::is_polymorph(value.fdef.sig .parameter_t) {
10671068 let node = typechecking::walk_Def_with_type_argument(value.node, parameter_t, context, typechecking::make_state(value.module))
10681069 let value = node.value.def_.function.value
10691070 return value
@@ -1081,9 +1082,10 @@ export def typecheck(value: &Value) {
10811082 value.phase = Phase::COMPILED
10821083 let state = typechecking::make_state(value.module)
10831084 if value.node.kind == parser::NodeKind::DEF {
1085+ assert value.kind == ValueKind::FUNCTION
10841086 //let tpe = typechecking::lookup_parameters(value.node, value.state)
1085- let tpe = value.tpe.resolve()
1086- if tpe.kind == typechecking::TypeKind::FUNCTION and not typechecking::is_polymorph(tpe .parameter_t) {
1087+ let fdef = value.fdef
1088+ if not typechecking::is_polymorph(fdef.sig .parameter_t) {
10871089 state.context = value.node.scope
10881090 typechecking::walk_Def(value.node, state)
10891091 value.tpe = value.node.tpe
@@ -1178,7 +1180,7 @@ export def get_function_check(
11781180 }
11791181
11801182 // Check for polymorphic instances
1181- if is_global(scope) and (not first_function or typechecking::is_polymorph(first_function.tpe.resolve() .parameter_t)) {
1183+ if is_global(scope) and (not first_function or typechecking::is_polymorph(first_function.fdef.sig .parameter_t)) {
11821184 var root_scope = context.module.scope
11831185 var new_score = std::MAX_INT32
11841186
@@ -1199,7 +1201,7 @@ export def get_function_check(
11991201 }
12001202 }
12011203 }
1202- } else if first_function and typechecking::is_polymorph(first_function.tpe.resolve() .parameter_t) {
1204+ } else if first_function and typechecking::is_polymorph(first_function.fdef.sig .parameter_t) {
12031205 if root_scope.polymorphics.contains(first_function.module.filename) {
12041206 // We found the function and we should only look into the polymorphs from this module
12051207 let poly_scope = root_scope.polymorphics(first_function.module.filename)
0 commit comments