diff options
| author | Bradley Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-13 09:33:57 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-13 09:33:57 -0400 |
| commit | 9839b47be3a43cd5b2cc058932921073c8d8d758 (patch) | |
| tree | 7e339ad7d83906d3fc27042bc46d18ece6776433 | |
| parent | 48529c593b435589f142e56367360bf84af3a070 (diff) | |
| parent | f418ac1782c34ce0b30f5d3ffd444128acc10c33 (diff) | |
Merge pull request #1006 from BradLewis/feat/proc-group-matrix-types
Resolve proc groups with matrix types
| -rw-r--r-- | src/server/analysis.odin | 39 | ||||
| -rw-r--r-- | tests/hover_test.odin | 32 |
2 files changed, 67 insertions, 4 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 7ee9a8f..d11d8b0 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -437,7 +437,7 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: Symbol, flags: ast. return is_symbol_same_typed(ast_context, a_symbol, b_symbol) && a_is_soa == b_is_soa case SymbolFixedArrayValue: b_value := b.value.(SymbolFixedArrayValue) - if !are_fixed_arrays_same_len(ast_context, a_value, b_value) { + if !are_same_size(ast_context, a_value.len, b_value.len) { return false } @@ -559,14 +559,45 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: Symbol, flags: ast. is_symbol_same_typed(ast_context, a_key_symbol, b_key_symbol) && is_symbol_same_typed(ast_context, a_value_symbol, b_value_symbol) \ ) + case SymbolMatrixValue: + b_value := b.value.(SymbolMatrixValue) + if !are_same_size(ast_context, a_value.x, b_value.x) { + return false + } + + if !are_same_size(ast_context, a_value.y, b_value.y) { + return false + } + + a_symbol: Symbol + b_symbol: Symbol + ok: bool + + set_ast_package_from_symbol_scoped(ast_context, a) + + a_symbol, ok = resolve_type_expression(ast_context, a_value.expr) + + if !ok { + return false + } + + set_ast_package_from_symbol_scoped(ast_context, b) + + b_symbol, ok = resolve_type_expression(ast_context, b_value.expr) + + if !ok { + return false + } + + return is_symbol_same_typed(ast_context, a_symbol, b_symbol) } return false } -are_fixed_arrays_same_len :: proc(ast_context: ^AstContext, a, b: SymbolFixedArrayValue) -> bool { - if a_symbol, ok := resolve_type_expression(ast_context, a.len); ok { - if b_symbol, ok := resolve_type_expression(ast_context, b.len); ok { +are_same_size :: proc(ast_context: ^AstContext, a, b: ^ast.Expr) -> bool { + if a_symbol, ok := resolve_type_expression(ast_context, a); ok { + if b_symbol, ok := resolve_type_expression(ast_context, b); ok { if a_len, ok := a_symbol.value.(SymbolUntypedValue); ok && a_len.type == .Integer { if b_len, ok := b_symbol.value.(SymbolUntypedValue); ok && b_len.type == .Integer { return a_len.tok.text == b_len.tok.text diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 72a68b5..51e53bf 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -4680,6 +4680,38 @@ ast_hover_using_bit_field_struct :: proc(t: ^testing.T) { } test.expect_hover(t, &source, "bit_field.c: u8 | 8") } + +@(test) +ast_hover_proc_group_parapoly_matrix :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + + mul :: proc { + matrix_mul, + matrix_mul_differ, + } + + @(require_results) + matrix_mul :: proc "contextless" (a, b: $M/matrix[$N, N]$E) -> (c: M) + where !IS_ARRAY(E), IS_NUMERIC(E) #no_bounds_check { + return a * b + } + + @(require_results) + matrix_mul_differ :: proc "contextless" (a: $A/matrix[$I, $J]$E, b: $B/matrix[J, $K]E) -> (c: matrix[I, K]E) + where !IS_ARRAY(E), IS_NUMERIC(E), I != K #no_bounds_check { + return a * b + } + + main :: proc() { + a: matrix[3,3]int + b: matrix[3,2]int + c{*} := mul(a, b) + } + `, + } + test.expect_hover(t, &source, "test.c: matrix[3,2]int") +} /* Waiting for odin fix |