diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-11-06 05:15:13 -0500 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-11-06 05:15:13 -0500 |
| commit | 0b7271488d9f339f0be3a0f7ccb81dd2d5dfb7df (patch) | |
| tree | 39cb7ca9b1fceffc8fd9758c3992e038f372d053 | |
| parent | 10ea97356964e04bfe522a8ad276528bdac35d48 (diff) | |
Resolve implicit selector switch statements before index expressions
| -rw-r--r-- | src/server/analysis.odin | 46 | ||||
| -rw-r--r-- | src/server/file_resolve.odin | 11 | ||||
| -rw-r--r-- | tests/references_test.odin | 40 |
3 files changed, 63 insertions, 34 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 1b14497..4a1980c 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -2367,29 +2367,6 @@ resolve_implicit_selector :: proc( } } - if position_context.index != nil { - symbol: Symbol - ok := false - if position_context.previous_index != nil { - symbol, ok = resolve_type_expression(ast_context, position_context.previous_index) - if !ok { - return {}, false - } - } else { - symbol, ok = resolve_type_expression(ast_context, position_context.index.expr) - if !ok { - return {}, false - } - } - - #partial switch value in symbol.value { - case SymbolFixedArrayValue: - return resolve_type_expression(ast_context, value.len) - case SymbolMapValue: - return resolve_type_expression(ast_context, value.key) - } - } - if position_context.comp_lit != nil && position_context.parent_comp_lit != nil { if symbol, ok := resolve_comp_literal(ast_context, position_context); ok { return resolve_implicit_selector_comp_literal(ast_context, position_context, symbol) @@ -2430,6 +2407,29 @@ resolve_implicit_selector :: proc( } } + if position_context.index != nil { + symbol: Symbol + ok := false + if position_context.previous_index != nil { + symbol, ok = resolve_type_expression(ast_context, position_context.previous_index) + if !ok { + return {}, false + } + } else { + symbol, ok = resolve_type_expression(ast_context, position_context.index.expr) + if !ok { + return {}, false + } + } + + #partial switch value in symbol.value { + case SymbolFixedArrayValue: + return resolve_type_expression(ast_context, value.len) + case SymbolMapValue: + return resolve_type_expression(ast_context, value.key) + } + } + if position_context.returns != nil && position_context.function != nil { return_index: int diff --git a/src/server/file_resolve.odin b/src/server/file_resolve.odin index 22d2d63..1b7a5c5 100644 --- a/src/server/file_resolve.odin +++ b/src/server/file_resolve.odin @@ -1,19 +1,8 @@ package server -import "core:fmt" -import "core:log" -import "core:mem" import "core:odin/ast" -import "core:odin/parser" import "core:odin/tokenizer" -import "core:path/filepath" -import path "core:path/slashpath" -import "core:reflect" -import "core:slice" -import "core:sort" -import "core:strconv" import "core:strings" -import "core:unicode/utf8" import "src:common" diff --git a/tests/references_test.odin b/tests/references_test.odin index d0d99f1..021033b 100644 --- a/tests/references_test.odin +++ b/tests/references_test.odin @@ -1480,3 +1480,43 @@ ast_references_union_member_pointer :: proc(t: ^testing.T) { test.expect_reference_locations(t, &source, locations[:]) } + +@(test) +ast_references_enum_with_enumerated_array :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + Foo :: enum { + A, B, + } + + Bar :: enum { + C, D, + } + + Bazz :: struct { + foobars: [Bar]Foo + } + + main :: proc() { + bazz: Bazz + bar: Bar + + foo: Foo + foo = .A{*} + + switch bazz.foobars[bar] { + case .A: + case .B: + } + } + `, + } + locations := []common.Location { + {range = {start = {line = 3, character = 4}, end = {line = 3, character = 5}}}, + {range = {start = {line = 19, character = 11}, end = {line = 19, character = 12}}}, + {range = {start = {line = 22, character = 10}, end = {line = 22, character = 11}}}, + } + + test.expect_reference_locations(t, &source, locations[:]) +} |