aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-06-11 22:14:46 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2021-06-11 22:14:46 +0200
commit2ff912a309dbb37a13fd9b62f25de82beb526a54 (patch)
tree72942220c7aef99ef5bf935b17b26beb6d4dca6e /src
parent8fd54ff1c06c9a99398e834fb188c42b1bb9f8cb (diff)
support named arguments in overloading
Diffstat (limited to 'src')
-rw-r--r--src/server/action.odin2
-rw-r--r--src/server/analysis.odin34
2 files changed, 34 insertions, 2 deletions
diff --git a/src/server/action.odin b/src/server/action.odin
index ba1b367..44b3458 100644
--- a/src/server/action.odin
+++ b/src/server/action.odin
@@ -13,4 +13,4 @@ CodeActionClientCapabilities :: struct {
CodeActionOptions :: struct {
codeActionKinds: []CodeActionKind,
resolveProvider: bool,
-}
+} \ No newline at end of file
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 8e56322..15ab92e 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -630,6 +630,21 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: index.Symbol) -> bo
return false;
}
+get_field_list_name_index :: proc(name: string, field_list: []^ast.Field) -> (int, bool) {
+
+ for field, i in field_list {
+ for field_name in field.names {
+ if ident, ok := field_name.derived.(ast.Ident); ok {
+ if name == ident.name {
+ return i, true;
+ }
+ }
+ }
+ }
+
+ return 0, false;
+}
+
/*
Figure out which function the call expression is using out of the list from proc group
*/
@@ -673,12 +688,29 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou
call_symbol: index.Symbol;
arg_symbol: index.Symbol;
ok: bool;
+ i := i;
if _, ok = arg.derived.(ast.Bad_Expr); ok {
continue;
}
- call_symbol, ok = resolve_type_expression(ast_context, arg);
+ //named parameter
+ if field, is_field := arg.derived.(ast.Field_Value); is_field {
+ call_symbol, ok = resolve_type_expression(ast_context, field.value);
+
+ if !ok {
+ break next_fn;
+ }
+
+ if ident, is_ident := field.field.derived.(ast.Ident); is_ident {
+ i, ok = get_field_list_name_index(field.field.derived.(ast.Ident).name, procedure.arg_types);
+ } else {
+ break next_fn;
+ }
+
+ } else {
+ call_symbol, ok = resolve_type_expression(ast_context, arg);
+ }
if !ok {
break next_fn;