aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-28 20:28:57 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-28 20:28:57 -0400
commitd36eccd1ed440c14f6b0138daeaebd206cd1d208 (patch)
treeefa6052a920ac301e14cd5d8a09fb109c89001ec
parent8fbda6ec890ec1d5cf4b886898877b2abb6b9126 (diff)
Correct resolving binary expr implicit selector expr
-rw-r--r--src/server/analysis.odin4
-rw-r--r--tests/references_test.odin34
2 files changed, 36 insertions, 2 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 9b2bc2b..9afdbc2 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -2132,9 +2132,9 @@ resolve_implicit_selector :: proc(
if position_context.binary != nil {
if position_in_node(position_context.binary.left, position_context.position) {
- return resolve_type_expression(ast_context, position_context.binary.right)
- } else {
return resolve_type_expression(ast_context, position_context.binary.left)
+ } else if position_in_node(position_context.binary.left, position_context.position) {
+ return resolve_type_expression(ast_context, position_context.binary.right)
}
}
diff --git a/tests/references_test.odin b/tests/references_test.odin
index c9c4891..2464924 100644
--- a/tests/references_test.odin
+++ b/tests/references_test.odin
@@ -1228,3 +1228,37 @@ ast_references_nested_switch_cases :: proc(t: ^testing.T) {
test.expect_reference_locations(t, &source, locations[:])
}
+
+@(test)
+ast_references_switch_cases_binary_expr :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ Foo :: enum {
+ A,
+ B{*},
+ }
+
+ Bar :: enum {
+ C,
+ D,
+ }
+
+ main :: proc() {
+ foo: Foo
+ bar: Bar
+
+ switch foo {
+ case .A:
+ if bar == .C {}
+ case .B:
+ }
+ }
+ `,
+ }
+ locations := []common.Location {
+ {range = {start = {line = 3, character = 3}, end = {line = 3, character = 4}}},
+ {range = {start = {line = 18, character = 9}, end = {line = 18, character = 10}}},
+ }
+
+ test.expect_reference_locations(t, &source, locations[:])
+}