aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-28 19:05:23 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-28 19:05:23 -0400
commitab4f9363beeba79e26fdbcd61eff293ac50d6ef5 (patch)
tree8fb8f592e7bebe3479fbbeb8d51d0baa4021f4c4
parent9f911012c3496fdc5e56733f0e7e52229ec37726 (diff)
Correctly resolve implicit selector within a switch case
-rw-r--r--src/server/analysis.odin19
-rw-r--r--tests/hover_test.odin26
2 files changed, 43 insertions, 2 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index cde9c5d..b042c65 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -2180,8 +2180,23 @@ resolve_implicit_selector :: proc(
}
if position_context.switch_stmt != nil {
- if symbol, ok := resolve_type_expression(ast_context, position_context.switch_stmt.cond); ok {
- return symbol, ok
+ if position_in_node(position_context.switch_stmt.cond, position_context.position) {
+ if symbol, ok := resolve_type_expression(ast_context, position_context.switch_stmt.cond); ok {
+ return symbol, ok
+ }
+ }
+ if body, ok := position_context.switch_stmt.body.derived.(^ast.Block_Stmt); ok {
+ for stmt in body.stmts {
+ if cc, ok := stmt.derived.(^ast.Case_Clause); ok {
+ for item in cc.list {
+ if position_in_node(item, position_context.position) {
+ if symbol, ok := resolve_type_expression(ast_context, position_context.switch_stmt.cond); ok {
+ return symbol, ok
+ }
+ }
+ }
+ }
+ }
}
}
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index adddb89..4889df6 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -4417,6 +4417,32 @@ ast_hover_defer_statement :: proc(t: ^testing.T) {
}
test.expect_hover(t, &source, "test.s: struct {\n\tbar: int,\n}")
}
+
+@(test)
+ast_hover_implicit_selector_return :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+
+ Foo :: enum {
+ A,
+ B,
+ }
+
+ Bar :: enum {
+ A,
+ B,
+ }
+
+ main :: proc(foo: Foo) -> Bar {
+ switch foo {
+ case .A:
+ return .A{*}
+ }
+ }
+ `
+ }
+ test.expect_hover(t, &source, "test.Bar: .A")
+}
/*
Waiting for odin fix