aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2025-06-05 19:11:35 +0200
committerGitHub <noreply@github.com>2025-06-05 19:11:35 +0200
commitc2a2283bf4e0cc2c2b25a6ee2014a18c3b11f3c7 (patch)
treef12e8c7c50acb9365cdf947e370a8f2de5189ce9
parent4fb3c51850eadffe0091dcd297ff284526dca601 (diff)
parent0e3ef1f2d7a9b0ee19a4b12c3dfadf15a8d5f4b2 (diff)
Merge pull request #647 from BradLewis/master
Resolve assignments before switch statements position context
-rw-r--r--src/server/analysis.odin9
-rw-r--r--tests/definition_test.odin39
2 files changed, 43 insertions, 5 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 7202fe2..7f0007e 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1669,12 +1669,7 @@ resolve_implicit_selector :: proc(
}
}
- if position_context.switch_stmt != nil {
- return resolve_type_expression(ast_context, position_context.switch_stmt.cond)
- }
-
if position_context.assign != nil && len(position_context.assign.lhs) == len(position_context.assign.rhs) {
-
for _, i in position_context.assign.lhs {
if position_in_node(position_context.assign.rhs[i], position_context.position) {
return resolve_type_expression(ast_context, position_context.assign.lhs[i])
@@ -1682,6 +1677,10 @@ resolve_implicit_selector :: proc(
}
}
+ if position_context.switch_stmt != nil {
+ return resolve_type_expression(ast_context, position_context.switch_stmt.cond)
+ }
+
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)
diff --git a/tests/definition_test.odin b/tests/definition_test.odin
index cd32628..ced4256 100644
--- a/tests/definition_test.odin
+++ b/tests/definition_test.odin
@@ -353,3 +353,42 @@ ast_goto_implicit_enum_infer_from_function :: proc(t: ^testing.T) {
test.expect_definition_locations(t, &source, {location})
}
+
+@(test)
+ast_goto_implicit_enum_infer_from_assignment_within_switch :: proc(t: ^testing.T) {
+ source := test.Source{
+ main = `package test
+ Bar :: enum {
+ Bar1,
+ Bar2,
+ }
+
+ Foo :: enum {
+ Foo1,
+ Foo2,
+ }
+
+
+ main :: proc() {
+ my_foo: Foo
+ my_bar: Bar
+ switch my_foo {
+ case .Foo1:
+ my_bar = .B{*}ar2
+ case .Foo2:
+ my_bar = .Bar1
+ }
+ }
+ `,
+ packages = {},
+ }
+
+ location := common.Location {
+ range = {
+ start = {line = 3, character = 3},
+ end = {line = 3, character = 7},
+ },
+ }
+
+ test.expect_definition_locations(t, &source, {location})
+}