aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-04-28 16:32:29 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2021-04-28 16:32:29 +0200
commit7ce7eed0eada14fd650b327fcfdee6b302f231aa (patch)
treeff3b8f31d947794bc6b992e6d3a6142f64adfd09
parentccb615d87742e9f79da905324e8674eb78ecdf6f (diff)
support for many symbol values in procedure overload
-rw-r--r--src/server/analysis.odin112
-rw-r--r--tests/signatures_test.odin47
2 files changed, 147 insertions, 12 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index d9ccb22..020f433 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -499,19 +499,110 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.Symbol) -> bo
a.name == b.name &&
a.pkg == b.pkg {
return true;
- } else {
- return false;
- }
+ }
- /*
- #partial switch s in a.value {
- case index.SymbolBasicValue:
-
+ #partial switch a_value in a.value {
+ case index.SymbolBasicValue, index.SymbolStructValue, index.SymbolEnumValue, index.SymbolUnionValue, index.SymbolBitSetValue:
+ if a.name == b.name && a.pkg == b.pkg {
+ return true;
+ }
+ case index.SymbolSliceValue:
+ b_value := b.value.(index.SymbolSliceValue);
+
+ a_symbol: index.Symbol;
+ b_symbol: index.Symbol;
+ ok: bool;
+
+ a_symbol, ok = resolve_type_expression(ast_context, a_value.expr);
+
+ if !ok {
+ return false;
+ }
+
+ b_symbol, ok = resolve_type_expression(ast_context, b_value.expr);
+
+ if !ok {
+ return false;
+ }
+
+ return is_symbol_same_typed(ast_context, a_symbol, b_symbol);
+ case index.SymbolFixedArrayValue:
+ b_value := b.value.(index.SymbolFixedArrayValue);
+
+ a_symbol: index.Symbol;
+ b_symbol: index.Symbol;
+ ok: bool;
+
+ a_symbol, ok = resolve_type_expression(ast_context, a_value.expr);
+
+ if !ok {
+ return false;
+ }
+
+ b_symbol, ok = resolve_type_expression(ast_context, b_value.expr);
+
+ if !ok {
+ return false;
+ }
+
+ return is_symbol_same_typed(ast_context, a_symbol, b_symbol);
+ case index.SymbolDynamicArrayValue:
+ b_value := b.value.(index.SymbolDynamicArrayValue);
+
+ a_symbol: index.Symbol;
+ b_symbol: index.Symbol;
+ ok: bool;
+
+ a_symbol, ok = resolve_type_expression(ast_context, a_value.expr);
+
+ if !ok {
+ return false;
+ }
+
+ b_symbol, ok = resolve_type_expression(ast_context, b_value.expr);
+
+ if !ok {
+ return false;
+ }
+
+ return is_symbol_same_typed(ast_context, a_symbol, b_symbol);
+ case index.SymbolMapValue:
+ b_value := b.value.(index.SymbolMapValue);
+
+ a_key_symbol: index.Symbol;
+ b_key_symbol: index.Symbol;
+ a_value_symbol: index.Symbol;
+ b_value_symbol: index.Symbol;
+ ok: bool;
+
+ a_key_symbol, ok = resolve_type_expression(ast_context, a_value.key);
+
+ if !ok {
+ return false;
+ }
+
+ b_key_symbol, ok = resolve_type_expression(ast_context, b_value.key);
+
+ if !ok {
+ return false;
+ }
+
+ a_value_symbol, ok = resolve_type_expression(ast_context, a_value.value);
+
+ if !ok {
+ return false;
+ }
+
+ b_value_symbol, ok = resolve_type_expression(ast_context, b_value.value);
+
+ if !ok {
+ return false;
+ }
+
+ return is_symbol_same_typed(ast_context, a_key_symbol, b_key_symbol) && is_symbol_same_typed(ast_context, a_value_symbol, b_value_symbol);
}
- */
-
- return true;
+ return false;
}
/*
@@ -552,7 +643,6 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou
call_symbol, ok = resolve_type_expression(ast_context, arg);
if !ok {
- fmt.println("call_symbol failed");
break next_fn;
}
diff --git a/tests/signatures_test.odin b/tests/signatures_test.odin
index 9877577..b1a71e1 100644
--- a/tests/signatures_test.odin
+++ b/tests/signatures_test.odin
@@ -127,4 +127,49 @@ ast_proc_group_signature_distinct_basic_types :: proc(t: ^testing.T) {
};
test.expect_signature_labels(t, &source, {"test.distinct_function: proc(a: My_Int, c: int)"});
-} \ No newline at end of file
+}
+
+@(test)
+ast_proc_group_signature_struct :: proc(t: ^testing.T) {
+
+ source := test.Source {
+ main = `package test
+
+ My_Int :: distinct int;
+
+ My_Struct :: struct {
+ one: int,
+ two: int,
+ three: int,
+ }
+
+ distinct_function :: proc(a: My_Int, c: int) {
+
+ }
+
+ int_function :: proc(a: int, c: int) {
+
+ }
+
+ struct_function :: proc(a: int, b: My_Struct, c: int) {
+
+ }
+
+ group_function :: proc {
+ int_function,
+ distinct_function,
+ struct_function,
+ };
+
+ main :: proc() {
+ a: int;
+ b: My_Struct;
+ group_function(a, b, *)
+ }
+ `,
+ source_packages = {},
+ };
+
+ test.expect_signature_labels(t, &source, {"test.struct_function: proc(a: int, b: My_Struct, c: int)"});
+}
+