Skip to content

Commit

Permalink
Fix overloading type functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Aug 4, 2022
1 parent 0ee8461 commit 2e7d7c1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/compiler.pr
Original file line number Diff line number Diff line change
Expand Up @@ -6208,7 +6208,7 @@ export def create_builtin_functions {
create_constructors()
}

export let constructors = map::make(type &string, type &typechecking::Type)
export let constructors = map::make(type &typechecking::Type)
def create_constructors {
let state = toolchain::types_state

Expand Down Expand Up @@ -6318,7 +6318,7 @@ def create_constructor(copy: Value, this: Value, state: &State) {
}

// Vector of (function) Type
export let destructors = map::make(type &string, type &typechecking::Type)
export let destructors = map::make(type &typechecking::Type)
def create_destructors {
// Need to import the free function because the types module doesn't import cstd
let state = toolchain::types_state
Expand Down
2 changes: 1 addition & 1 deletion src/scope.pr
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def generate_function(scope: &Scope, node: &parser::Node, parameter_t: &Vector(t
let name_node = parser::make_identifier(name)
let parameter_t3 = typechecking::copy_parameter_t(found_member.parameter_t)
let return_t = typechecking::copy_return_t(found_member.return_t)
let types_map = map::make(type &string, type &typechecking::Type) // FIXME Ambiguous reference
let types_map = map::make(type &typechecking::Type)

if stpe.tc_args {
for var i in 0..vector::length(stpe.tc_tpe.parameter_t) {
Expand Down
9 changes: 5 additions & 4 deletions src/typechecking.pr
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,8 @@ export def overload_score(param_a: &Vector(NamedParameter), return_t: &Vector(&T
return_t = copy_return_t(return_t)

if vector::length(param_a) > vector::length(param_b) {
let not_default_param = (param_a[vector::length(param_b)]).value == null
let a = param_a[vector::length(param_b)]
let not_default_param = a.value == null or a.tpe.kind == TypeKind::TYPE
if vector::length(param_a) == vector::length(param_b) + 1 {
if not vector::peek(param_a).varargs and not_default_param {
return -1
Expand Down Expand Up @@ -2219,7 +2220,7 @@ export def do_type_lookup(node: &parser::Node, state: &State, current_type: &Typ
state.scope = scpe
return tpe
}
if not cache { cache = map::make(type &string, type &Type) }
if not cache { cache = map::make(type &Type) }
var cached_type = cache.get_or_default(type_name, null)
if cached_type != null {
state.scope = scpe
Expand Down Expand Up @@ -3240,7 +3241,7 @@ export def walk_Def(node: &parser::Node, state: &State) {

def check_is_recursive(tpe: &Type, types: &SMap(&Type) = null) -> bool {
if not tpe { return false }
if not types { types = map::make(type &string, type &Type) }
if not types { types = map::make(type &Type) }
if tpe.kind == TypeKind::STATIC_ARRAY {
return check_is_recursive(tpe.tpe, types)
}
Expand All @@ -3250,7 +3251,7 @@ def check_is_recursive(tpe: &Type, types: &SMap(&Type) = null) -> bool {
types[tpe.type_name] = tpe
}
for var i in 0..tpe.fields.size {
let new_types = map::make(type &string, type &Type)
let new_types = map::make(type &Type)
let keys = map::keys(types)
for var j in 0..keys.size {
new_types[keys[j]] = types[keys[j]]
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=0.3.0
VERSION=0.3.1

0 comments on commit 2e7d7c1

Please sign in to comment.