From 5e177c085afdea823cf635c22894f89855434d28 Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Sat, 29 Nov 2025 19:43:56 -0500 Subject: Correctly resolve type assertions with unary exprs --- src/server/locals.odin | 6 ++++++ tests/hover_test.odin | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/server/locals.odin b/src/server/locals.odin index a88a6d7..edebd85 100644 --- a/src/server/locals.odin +++ b/src/server/locals.odin @@ -283,6 +283,12 @@ get_generic_assignment :: proc( b := make_bool_ast(ast_context, v.type.pos, v.type.end) + append(results, b) + } + case ^Unary_Expr: + append(results, value) + if n, ok := v.expr.derived.(^Type_Assertion); ok { + b := make_bool_ast(ast_context, n.type.pos, n.type.end) append(results, b) } case ^Ternary_If_Expr: diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 06d3dce..81c732a 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -5716,6 +5716,60 @@ ast_hover_bitshift_integer_type :: proc(t: ^testing.T) { } test.expect_hover(t, &source, "test.bar: int") } + +@(test) +ast_hover_type_assertion_unary_value :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Foo :: union { + int, + f64, + } + + main :: proc() { + foo := Foo(0.0) + i{*} := &foo.(int) + } + `, + } + test.expect_hover(t, &source, "test.i: ^int") +} + +@(test) +ast_hover_type_assertion_unary_value_value :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Foo :: union { + int, + f64, + } + + main :: proc() { + foo := Foo(0.0) + i{*}, ok := &foo.(int) + } + `, + } + test.expect_hover(t, &source, "test.i: ^int") +} + +@(test) +ast_hover_type_assertion_unary_value_ok :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + Foo :: union { + int, + f64, + } + + main :: proc() { + foo := Foo(0.0) + i, ok{*} := &foo.(int) + } + `, + } + test.expect_hover(t, &source, "test.ok: bool") +} /* Waiting for odin fix -- cgit v1.2.3