From 53307cd6b31b031c9b718df66eec8ba2f56d7f7b Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Sun, 14 Sep 2025 08:19:46 -0400 Subject: Correct resolved types when slicing multi-pointers --- src/server/analysis.odin | 4 ++++ tests/hover_test.odin | 28 +++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/server/analysis.odin b/src/server/analysis.odin index d11d8b0..570a035 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1943,6 +1943,10 @@ resolve_slice_expression :: proc(ast_context: ^AstContext, slice_expr: ^ast.Slic case SymbolDynamicArrayValue: expr = v.expr case SymbolMultiPointerValue: + // Slicing multi-pointer behaviour outlined here: https://odin-lang.org/docs/overview/#multi-pointers + if slice_expr.high == nil { + return symbol, true + } expr = v.expr case SymbolUntypedValue: if v.type == .String { diff --git a/tests/hover_test.odin b/tests/hover_test.odin index 51e53bf..37d0362 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -4202,7 +4202,7 @@ ast_hover_untyped_string_index :: proc(t: ^testing.T) { } @(test) -ast_hover_multi_pointer_slice_range :: proc(t: ^testing.T) { +ast_hover_multi_pointer_slice_end_range :: proc(t: ^testing.T) { source := test.Source { main = `package test main :: proc() { @@ -4214,6 +4214,32 @@ ast_hover_multi_pointer_slice_range :: proc(t: ^testing.T) { test.expect_hover(t, &source, "test.bar: []int") } +@(test) +ast_hover_multi_pointer_slice_start_range :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + main :: proc() { + foo: [^]int + b{*}ar := foo[1:] + } + `, + } + test.expect_hover(t, &source, "test.bar: [^]int") +} + +@(test) +ast_hover_multi_pointer_slice_no_range :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + main :: proc() { + foo: [^]int + b{*}ar := foo[:] + } + `, + } + test.expect_hover(t, &source, "test.bar: [^]int") +} + @(test) ast_hover_binary_expr_with_type :: proc(t: ^testing.T) { source := test.Source { -- cgit v1.2.3