Skip to content

Commit

Permalink
Fix lookup by moving things up higher
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Oct 12, 2024
1 parent d03d06f commit 7f6a127
Showing 1 changed file with 51 additions and 50 deletions.
101 changes: 51 additions & 50 deletions src/scope.pr
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,57 @@ export def get_function_check(
return true, null
}
}

// Check for polymorphic instances
if is_global(scope) and (not first_function or first_function.tpe.is_polymorph) {
var root_scope = context.module.scope
var new_score = std::MAX_INT32

if root_scope.polymorphics {
// We need to check the path we took to get here and then see if
// there is a module under that path
var poly_value: &Value
if path.length > 0 {
let module_scope = get(root_scope, parser::make_identifier(@path.to_array()))
if module_scope and root_scope.polymorphics.contains(module_scope.module.filename) {
// If there is a module we can look into the polymorphic instances of that module
let poly_scope = root_scope.polymorphics(module_scope.module.filename)
if poly_scope {
let val = poly_scope.fields.get_or_default(name, null)
let new_code, new_value = find_function(poly_scope, id, val, parameter_t, *new_score, dry_run, context)
if new_value and new_score < score {
return new_code, new_value
}
}
}
} else if first_function and first_function.tpe.is_polymorph {
if root_scope.polymorphics.contains(first_function.module.filename) {
// We found the function and we should only look into the polymorphs from this module
let poly_scope = root_scope.polymorphics(first_function.module.filename)
if poly_scope {
let val = poly_scope.fields.get_or_default(name, null)
let new_code, new_value = find_function(poly_scope, id, val, parameter_t, *new_score, dry_run, context)
if new_value and new_score < score {
return new_code, new_value
}
}
}
} else {
// Otherwise we have a non qualified call, which means we need to look at ALL modules
for var module_name in @root_scope.polymorphics.keys() {
let poly_scope = root_scope.polymorphics(module_name)
if poly_scope {
let val = poly_scope.fields.get_or_default(name, null)
let new_code, new_value = find_function(poly_scope, id, val, parameter_t, *new_score, dry_run, context)
if new_value and new_score < score {
return new_code, new_value
}
}
}
}
}
}

// TODO We need to really check for the score here
if not value and re_exports {
if scope.re_exports {
Expand Down Expand Up @@ -1226,56 +1277,6 @@ export def get_function_check(
value = typecheck_function(value, id, scope, dry_run, parameter_t, context)
}

// Check for polymorphic instances
if is_global(scope) and (not first_function or first_function.tpe.is_polymorph) {
var root_scope = context.module.scope
var new_score = std::MAX_INT32

if root_scope.polymorphics {
// We need to check the path we took to get here and then see if
// there is a module under that path
var poly_value: &Value
if path.length > 0 {
let module_scope = get(root_scope, parser::make_identifier(@path.to_array()))
if module_scope and root_scope.polymorphics.contains(module_scope.module.filename) {
// If there is a module we can look into the polymorphic instances of that module
let poly_scope = root_scope.polymorphics(module_scope.module.filename)
if poly_scope {
let val = poly_scope.fields.get_or_default(name, null)
let new_code, new_value = find_function(poly_scope, id, val, parameter_t, *new_score, dry_run, context)
if new_value and new_score < score {
return new_code, new_value
}
}
}
} else if first_function and first_function.tpe.is_polymorph {
if root_scope.polymorphics.contains(first_function.module.filename) {
// We found the function and we should only look into the polymorphs from this module
let poly_scope = root_scope.polymorphics(first_function.module.filename)
if poly_scope {
let val = poly_scope.fields.get_or_default(name, null)
let new_code, new_value = find_function(poly_scope, id, val, parameter_t, *new_score, dry_run, context)
if new_value and new_score < score {
return new_code, new_value
}
}
}
} else {
// Otherwise we have a non qualified call, which means we need to look at ALL modules
for var module_name in @root_scope.polymorphics.keys() {
let poly_scope = root_scope.polymorphics(module_name)
if poly_scope {
let val = poly_scope.fields.get_or_default(name, null)
let new_code, new_value = find_function(poly_scope, id, val, parameter_t, *new_score, dry_run, context)
if new_value and new_score < score {
return new_code, new_value
}
}
}
}
}
}


return code, value
} else {
Expand Down

0 comments on commit 7f6a127

Please sign in to comment.