diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2023-12-17 21:37:54 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2023-12-17 21:37:54 +0100 |
| commit | 3796af429b7a504a4decdd153fb541f10068e198 (patch) | |
| tree | 9338b4fe71b8a0b06554c27f6aa05f639f38d6c8 | |
| parent | 0d125598671d97c6cdc535f40d194d566cb60376 (diff) | |
Fix issue with variables assigning in global space to procedures.
| -rw-r--r-- | src/server/analysis.odin | 19 | ||||
| -rw-r--r-- | tests/completions_test.odin | 63 |
2 files changed, 60 insertions, 22 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 9430118..c56f63c 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1585,8 +1585,8 @@ internal_resolve_type_identifier :: proc( ast_context: ^AstContext, node: ast.Ident, ) -> ( - Symbol, - bool, + _symbol: Symbol, + _ok: bool, ) { using ast @@ -1773,6 +1773,21 @@ internal_resolve_type_identifier :: proc( ast_context, v^, ) + case ^ast.Call_Expr: + call_symbol := internal_resolve_type_expression( + ast_context, + v.expr, + ) or_return + + proc_value := call_symbol.value.(SymbolProcedureValue) or_return + + if len(proc_value.return_types) >= 1 && + proc_value.return_types[0].type != nil { + return_symbol, ok = internal_resolve_type_expression( + ast_context, + proc_value.return_types[0].type, + ) + } case ^Struct_Type: return_symbol, ok = make_symbol_struct_from_ast( diff --git a/tests/completions_test.odin b/tests/completions_test.odin index 284792a..c3496e4 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -349,7 +349,7 @@ index_package_completion :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package My_Struct :: struct { @@ -481,7 +481,7 @@ ast_swizzle_completion :: proc(t: ^testing.T) { t, &source, ".", - { + { "x: f32", "y: f32", "z: f32", @@ -597,7 +597,7 @@ ast_for_in_for_from_different_package :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package My_Bar :: struct { @@ -903,7 +903,7 @@ ast_overload_with_any_int_index_completion :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package my_group :: proc{ @@ -947,7 +947,7 @@ ast_package_procedure_completion :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package my_proc :: proc() -> bool { @@ -1072,7 +1072,7 @@ ast_file_private_completion :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package @@ -1101,7 +1101,7 @@ ast_non_mutable_variable_struct_completion :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package My_Struct :: struct { a: int } @@ -1129,7 +1129,7 @@ ast_mutable_variable_struct_completion :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package My_Struct :: struct { a: int } @@ -1489,7 +1489,7 @@ ast_maybe_index_completion :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package Maybe :: union($T: typeid) {T} @@ -1615,7 +1615,7 @@ ast_index_proc_parameter_completion :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package My_Struct :: struct { @@ -1728,7 +1728,7 @@ ast_comp_lit_with_all_symbols_indexed_enum_implicit :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package Foo :: enum { @@ -1766,7 +1766,7 @@ ast_package_uppercase_test :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "My_package", source = `package My_package Foo :: enum { @@ -1808,7 +1808,7 @@ ast_index_enum_infer :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "My_package", source = `package My_package Foo :: enum { @@ -1840,7 +1840,7 @@ ast_index_enum_infer_call_expr :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package Foo :: enum { @@ -1998,7 +1998,7 @@ ast_union_with_type_from_different_package :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package My_Int :: int @@ -2161,7 +2161,7 @@ ast_completion_struct_with_same_name_in_pkg :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package A :: struct { @@ -2199,7 +2199,7 @@ ast_completion_method_with_type :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package A :: struct { @@ -2232,7 +2232,7 @@ ast_implicit_bitset_value_decl_from_package :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package Foo :: enum { Aa, Ab, Ac, Ad } @@ -2268,7 +2268,7 @@ ast_private_proc_ignore :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package @(private) @@ -2300,7 +2300,7 @@ ast_bitset_assignment_diff_pkg :: proc(t: ^testing.T) { append( &packages, - test.Package{ + test.Package { pkg = "my_package", source = `package my_package Foo :: enum { Aa, Ab, Ac, Ad } @@ -2384,3 +2384,26 @@ ast_generic_struct_with_array :: proc(t: ^testing.T) { test.expect_completion_details(t, &source, ".", {"Test_Inner.b: int"}) } + +@(test) +ast_assign_to_global_function :: proc(t: ^testing.T) { + packages := make([dynamic]test.Package) + + source := test.Source { + main = `package test + import "my_package" + get_foo :: proc() -> string { + + } + + global_foo := get_foo() + + main :: proc() { + global_fo{*} + } + `, + packages = packages[:], + } + + test.expect_completion_details(t, &source, "", {"test.global_foo: string"}) +} |