diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2025-06-16 20:19:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-16 20:19:25 +0200 |
| commit | c968d52925282cc7587896aeef076ba0df6ebd0c (patch) | |
| tree | a0c40300283a7076fcc23913950641b48602e3c4 | |
| parent | 1f56bbb7e4f350e618942d7f4cb329511f2ece1f (diff) | |
| parent | f7e0a3c5b5b5c6674a53db1a94fef18d9ad2fdc6 (diff) | |
Merge pull request #671 from BradLewis/fix/overload-proc-parametric-types
Correctly resolve overloaded call argument types with parametric types
| -rw-r--r-- | src/server/analysis.odin | 4 | ||||
| -rw-r--r-- | tests/hover_test.odin | 76 |
2 files changed, 78 insertions, 2 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 9daf67a..59acd5c 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -707,9 +707,9 @@ resolve_function_overload :: proc(ast_context: ^AstContext, group: ast.Proc_Grou } if proc_arg.type != nil { - arg_symbol, ok = resolve_type_expression(ast_context, proc_arg.type) + arg_symbol, ok = resolve_call_arg_type_expression(ast_context, proc_arg.type) } else { - arg_symbol, ok = resolve_type_expression(ast_context, proc_arg.default_value) + arg_symbol, ok = resolve_call_arg_type_expression(ast_context, proc_arg.default_value) } if !ok { diff --git a/tests/hover_test.odin b/tests/hover_test.odin index ab6fa28..02069f1 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -1234,6 +1234,82 @@ ast_hover_inside_multi_pointer_struct :: proc(t: ^testing.T) { test.expect_hover(t, &source, "S2.field: S3") } + +@(test) +ast_hover_proc_overloading_parametric_type :: proc(t: ^testing.T) { + packages := make([dynamic]test.Package, context.temp_allocator) + + append( + &packages, + test.Package { + pkg = "my_package", + source = `package my_package + + Foo :: struct {} + `, + }, + ) + + source := test.Source { + main = `package test + import "my_package" + + new_ints :: proc($T: typeid, a, b: int) -> ^T {} + new_int_string :: proc($T: typeid, a: int, s: string) -> ^T {} + + new :: proc { + new_ints, + new_int_string, + } + + + main :: proc() { + f{*}oo := new(my_package.Foo, 1, 2) + } + `, + packages = packages[:], + } + + test.expect_hover(t, &source, "test.foo: ^my_package.Foo :: struct {}") +} + +@(test) +ast_hover_proc_overloading_parametric_type_external_package :: proc(t: ^testing.T) { + packages := make([dynamic]test.Package, context.temp_allocator) + + append( + &packages, + test.Package { + pkg = "my_package", + source = `package my_package + new_ints :: proc($T: typeid, a, b: int) -> ^T {} + new_int_string :: proc($T: typeid, a: int, s: string) -> ^T {} + + new :: proc { + new_ints, + new_int_string, + } + + Foo :: struct {} + `, + }, + ) + + source := test.Source { + main = `package test + + import "my_package" + + + main :: proc() { + f{*}oo := my_package.new(my_package.Foo, 1, 2) + } + `, + packages = packages[:], + } + + test.expect_hover(t, &source, "test.foo: ^my_package.Foo :: struct {}") +} /* Waiting for odin fix |