diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-06-11 19:19:10 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-06-11 19:19:10 +0200 |
| commit | f14f7ee50ba4b47f7a23e47fe61657b36f3014be (patch) | |
| tree | fbbf066bf42fdbbdb30d234175ff678164972334 | |
| parent | 992db0756bd1a15ea0df2d600c7c950de5cd5070 (diff) | |
Improve enum gotos and fix generic issue
| -rw-r--r-- | src/server/analysis.odin | 2 | ||||
| -rw-r--r-- | src/server/generics.odin | 21 | ||||
| -rw-r--r-- | tests/definition_test.odin | 90 |
3 files changed, 112 insertions, 1 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index b6ae251..228eafa 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -2307,6 +2307,8 @@ resolve_location_implicit_selector :: proc( symbol: Symbol, ok: bool, ) { + ok = true + reset_ast_context(ast_context) set_ast_package_set_scoped(ast_context, ast_context.document_package) diff --git a/src/server/generics.odin b/src/server/generics.odin index 65271b2..9e915c3 100644 --- a/src/server/generics.odin +++ b/src/server/generics.odin @@ -261,6 +261,25 @@ resolve_poly :: proc( return true } } + case ^ast.Pointer_Type: + if call_pointer, ok := call_node.derived.(^ast.Pointer_Type); ok { + if poly_type, ok := p.elem.derived.(^ast.Poly_Type); ok { + if ident, ok := unwrap_ident(poly_type.type); ok { + save_poly_map(ident, call_pointer.elem, poly_map) + } + + if poly_type.specialization != nil { + return resolve_poly( + ast_context, + call_pointer.elem, + call_symbol, + p.elem, + poly_map, + ) + } + return true + } + } case ^ast.Comp_Lit: if comp_lit, ok := call_node.derived.(^ast.Comp_Lit); ok { if poly_type, ok := p.type.derived.(^ast.Poly_Type); ok { @@ -284,7 +303,7 @@ resolve_poly :: proc( return true } case: - log.panicf("Unhandled specialization %v", specialization.derived) + log.error("Unhandled specialization %v", specialization.derived) } return false diff --git a/tests/definition_test.odin b/tests/definition_test.odin index 98b055c..677736a 100644 --- a/tests/definition_test.odin +++ b/tests/definition_test.odin @@ -230,3 +230,93 @@ ast_goto_shadowed_value_decls :: proc(t: ^testing.T) { {{range = {{line = 2, character = 4}, {line = 2, character = 7}}}}, ) } + + +@(test) +ast_goto_implicit_enum_infer_from_assignment :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + My_Enum :: enum { + One, + Two, + Three, + Four, + } + + my_function :: proc() { + my_enum: My_Enum + my_enum = .Fo{*}ur + } + `, + packages = {}, + } + + location := common.Location { + range = { + start = {line = 5, character = 3}, + end = {line = 5, character = 7}, + }, + } + + test.expect_definition_locations(t, &source, {location}) +} + +@(test) +ast_goto_implicit_enum_infer_from_return :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + My_Enum :: enum { + One, + Two, + Three, + Four, + } + + my_function :: proc() -> My_Enum { + return .Fo{*}ur + } + `, + packages = {}, + } + + location := common.Location { + range = { + start = {line = 5, character = 3}, + end = {line = 5, character = 7}, + }, + } + + test.expect_definition_locations(t, &source, {location}) +} + +@(test) +ast_goto_implicit_enum_infer_from_function :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + My_Enum :: enum { + One, + Two, + Three, + Four, + } + + my_fn :: proc(my_enum: My_Enum) { + + } + + my_function :: proc() { + my_fn(.Fo{*}ur) + } + `, + packages = {}, + } + + location := common.Location { + range = { + start = {line = 5, character = 3}, + end = {line = 5, character = 7}, + }, + } + + test.expect_definition_locations(t, &source, {location}) +} |