diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-07 14:01:31 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-07-07 14:04:01 -0400 |
| commit | 81dfb4de0cd5855e2cc719abe8d3f44f951949dc (patch) | |
| tree | 4142aaf2395e528035bd9a7745a01b83a855d365 | |
| parent | 0a254711a65bea797dc64946d64b9c614460a93a (diff) | |
Fix issue resolving struct fields when constructed in a return statement
| -rw-r--r-- | src/server/analysis.odin | 53 | ||||
| -rw-r--r-- | tests/references_test.odin | 31 |
2 files changed, 57 insertions, 27 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index b5089b1..b91840e 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1856,33 +1856,6 @@ resolve_implicit_selector :: proc( } } - if position_context.returns != nil && position_context.function != nil { - return_index: int - - if position_context.returns.results == nil { - return {}, false - } - - for result, i in position_context.returns.results { - if position_in_node(result, position_context.position) { - return_index = i - break - } - } - - if position_context.function.type == nil { - return {}, false - } - - if position_context.function.type.results == nil { - return {}, false - } - - if len(position_context.function.type.results.list) > return_index { - return resolve_type_expression(ast_context, position_context.function.type.results.list[return_index].type) - } - } - if position_context.value_decl != nil && position_context.value_decl.type != nil { return resolve_type_expression(ast_context, position_context.value_decl.type) } @@ -1982,6 +1955,32 @@ resolve_implicit_selector :: proc( } } + if position_context.returns != nil && position_context.function != nil { + return_index: int + + if position_context.returns.results == nil { + return {}, false + } + + for result, i in position_context.returns.results { + if position_in_node(result, position_context.position) { + return_index = i + break + } + } + + if position_context.function.type == nil { + return {}, false + } + + if position_context.function.type.results == nil { + return {}, false + } + + if len(position_context.function.type.results.list) > return_index { + return resolve_type_expression(ast_context, position_context.function.type.results.list[return_index].type) + } + } return {}, false } diff --git a/tests/references_test.odin b/tests/references_test.odin index cac6e9e..c4665d8 100644 --- a/tests/references_test.odin +++ b/tests/references_test.odin @@ -792,3 +792,34 @@ ast_reference_struct_and_enum_variant_same_name :: proc(t: ^testing.T) { test.expect_reference_locations(t, &source, locations[:], expect_excluded) } + +@(test) +ast_reference_enum_variants_comp_lit_return :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + Foo :: enum { + A, + B, + } + + Bar :: struct { + foo: Foo, + } + + foo :: proc() -> Bar { + return Bar { + foo = .A{*}, + } + } + + `, + } + + locations := []common.Location { + {range = {start = {line = 3, character = 3}, end = {line = 3, character = 4}}}, + {range = {start = {line = 13, character = 11}, end = {line = 13, character = 12}}}, + } + + test.expect_reference_locations(t, &source, locations[:]) +} |