diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-01-09 02:45:42 +0100 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-01-09 02:45:42 +0100 |
| commit | 2e6c803dedce3c85c55a36a1bd8fb04edc65f65c (patch) | |
| tree | b01a93f074babb711a7b537ddb11d032787c57c8 /src | |
| parent | 661f1afc57eca524a6d25ea533d43206e21be68d (diff) | |
Fix function overloading with function returns.
Diffstat (limited to 'src')
| -rw-r--r-- | src/analysis/analysis.odin | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/analysis/analysis.odin b/src/analysis/analysis.odin index 7e14bbe..2f69536 100644 --- a/src/analysis/analysis.odin +++ b/src/analysis/analysis.odin @@ -564,7 +564,7 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.Symbol, flags case index.SymbolBasicValue: return a.name == b.name && a.pkg == b.pkg case index.SymbolStructValue, index.SymbolEnumValue, index.SymbolUnionValue, index.SymbolBitSetValue: - return a.name == b.name && a.pkg == b.pkg; + return a.name == b.name && a.pkg == b.pkg; case index.SymbolSliceValue: b_value := b.value.(index.SymbolSliceValue); @@ -694,7 +694,7 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou next_fn: if f, ok := resolve_type_expression(ast_context, arg_expr); ok { - if ast_context.call == nil || len(ast_context.call.args) == 0 { + if call_expr == nil || len(call_expr.args) == 0 { append(&candidates, f); break next_fn; } @@ -738,7 +738,6 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou } else { break next_fn; } - } else { call_symbol, ok = resolve_type_expression(ast_context, arg); } @@ -747,6 +746,15 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou break next_fn; } + if p, ok := call_symbol.value.(index.SymbolProcedureValue); ok { + if len(p.return_types) != 1 { + break next_fn; + } + if s, ok := resolve_type_expression(ast_context, p.return_types[0].type); ok { + call_symbol = s; + } + } + if procedure.arg_types[i].type != nil { arg_symbol, ok = resolve_type_expression(ast_context, procedure.arg_types[i].type); } else { @@ -759,15 +767,14 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou if !is_symbol_same_typed(ast_context, call_symbol, arg_symbol, procedure.arg_types[i].flags) { break next_fn; - } - + } } append(&candidates, f); } } } - + if len(candidates) > 1 { return index.Symbol { type = candidates[0].type, |