aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-09-17 08:26:07 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-09-17 08:26:07 -0400
commit2d7c8bedac7d3e4780a8507a8b00b6dea254cd0d (patch)
tree05f6a69736343d24288c7847361680dcc52b0011
parent379c55200570277d68a78006844cd32b1802f328 (diff)
Correctly resolve local if and when ternary expressions
-rw-r--r--src/server/analysis.odin4
-rw-r--r--src/server/locals.odin4
-rw-r--r--tests/hover_test.odin13
3 files changed, 19 insertions, 2 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 113f913..44063d6 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1185,10 +1185,10 @@ internal_resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Ex
out^ = make_symbol_poly_type_from_ast(ast_context, v.type)
return true
case ^ast.Ternary_If_Expr:
- out^, ok = resolve_type_expression(ast_context, v.x)
+ ok = internal_resolve_type_expression(ast_context, v.x, out)
return ok
case ^ast.Ternary_When_Expr:
- out^, ok = resolve_type_expression(ast_context, v.x)
+ ok = internal_resolve_type_expression(ast_context, v.x, out)
return ok
case:
log.warnf("default node kind, internal_resolve_type_expression: %v", v)
diff --git a/src/server/locals.odin b/src/server/locals.odin
index 63a1452..3de2923 100644
--- a/src/server/locals.odin
+++ b/src/server/locals.odin
@@ -272,6 +272,10 @@ get_generic_assignment :: proc(
append(results, b)
}
+ case ^Ternary_If_Expr:
+ get_generic_assignment(file, v.x, ast_context, results, calls, flags, is_mutable)
+ case ^Ternary_When_Expr:
+ get_generic_assignment(file, v.x, ast_context, results, calls, flags, is_mutable)
case:
append(results, value)
}
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index 402e38a..071bcba 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -4821,6 +4821,19 @@ ast_hover_enum_implicit_if_statement :: proc(t: ^testing.T) {
}
test.expect_hover(t, &source, "test.Foo: .A")
}
+
+@(test)
+ast_hover_if_ternary_expr :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ main :: proc() {
+ foo: []int
+ ba{*}r := len(foo) if true else 2
+ }
+ `,
+ }
+ test.expect_hover(t, &source, "test.bar: int")
+}
/*
Waiting for odin fix