diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-06-28 11:16:43 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-06-28 11:32:44 -0400 |
| commit | 0dba0ec89f59b7998f62536bf6ff68cab428a64a (patch) | |
| tree | d7817977778ffbe78af29d29ed94dd3b10e5321a | |
| parent | 91d4bc816f63f96a69ac0dd9a36358214c655d68 (diff) | |
Correctly resolve references within a switch case statement
| -rw-r--r-- | src/server/file_resolve.odin | 1 | ||||
| -rw-r--r-- | tests/references_test.odin | 36 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/server/file_resolve.odin b/src/server/file_resolve.odin index 18f4fae..b8e9059 100644 --- a/src/server/file_resolve.odin +++ b/src/server/file_resolve.odin @@ -391,6 +391,7 @@ resolve_node :: proc(node: ^ast.Node, data: ^FileResolveData) { case ^Defer_Stmt: resolve_node(n.stmt, data) case ^Case_Clause: + local_scope(data, n) resolve_nodes(n.list, data) resolve_nodes(n.body, data) case ^Type_Switch_Stmt: diff --git a/tests/references_test.odin b/tests/references_test.odin index 87195b6..7b4bcf6 100644 --- a/tests/references_test.odin +++ b/tests/references_test.odin @@ -416,3 +416,39 @@ ast_reference_cast_proc_param_with_param_expr :: proc (t: ^testing.T) { test.expect_reference_locations(t, &source, locations[:]) } + +@(test) +ast_reference_variable_in_switch_case :: proc (t: ^testing.T) { + source := test.Source { + main = `package test + + Bar :: enum { + Bar1, + Bar2, + } + + Foo :: struct { + foo1: int, + } + + main :: proc() { + bar: Bar + + #partial switch bar { + case .Bar1: + foo := Foo{} + f{*}oo.foo1 = 2 + } + } + `, + } + + locations := []common.Location { + {range = {start = {line = 17, character = 4}, end = {line = 17, character = 7}}}, + {range = {start = {line = 17, character = 4}, end = {line = 17, character = 7}}}, + } + + test.expect_reference_locations(t, &source, locations[:]) +} + + |