From 8a014d117e86178e5b9ab5c91fd5c92d2ebf9422 Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Thu, 25 Sep 2025 08:13:19 -0400 Subject: Correctly infer types when indexing matrices --- src/server/analysis.odin | 7 +++++++ tests/hover_test.odin | 28 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 9ee621a..2278e00 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1297,6 +1297,13 @@ resolve_index_expr :: proc(ast_context: ^AstContext, v: ^ast.Index_Expr) -> (Sym return indexed, true } return {}, false + case SymbolMatrixValue: + value := SymbolFixedArrayValue{ + expr = v2.expr, + len = v2.x, + } + indexed.value = value + return indexed, true } diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 345e9f9..d0b844e 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -5033,7 +5033,6 @@ ast_hover_proc_overload_basic_type_alias :: proc(t: ^testing.T) { ast_hover_proc_overload_nil_pointer :: proc(t: ^testing.T) { source := test.Source { main = `package test - import "my_package" foo_int :: proc(i: int) {} foo_ptr :: proc(s: ^string) {} @@ -5086,6 +5085,33 @@ ast_hover_package_proc_naming_conflicting_with_another_package :: proc(t: ^testi test.expect_hover(t, &source, "my_package.foo :: proc()") } + +@(test) +ast_hover_matrix_index :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + main :: proc() { + foo: matrix[3, 2]f32 + a{*} := foo[0] + } + `, + } + test.expect_hover(t, &source, "test.a: [3]f32") +} + +@(test) +ast_hover_matrix_index_twice :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + main :: proc() { + foo: matrix[2, 3]f32 + a := foo[0] + b{*} := a[0] + } + `, + } + test.expect_hover(t, &source, "test.b: f32") +} /* Waiting for odin fix -- cgit v1.2.3