aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBradley Lewis <22850972+BradLewis@users.noreply.github.com>2025-09-14 08:32:28 -0400
committerGitHub <noreply@github.com>2025-09-14 08:32:28 -0400
commite23480a32c5c9089c3449a379226b6334916a322 (patch)
tree1636f71bc2bc50481ccc9e294249e9496021e1a5
parente1bbebd377a15b1833c89fa00c23edb8e702c1e3 (diff)
parent53307cd6b31b031c9b718df66eec8ba2f56d7f7b (diff)
Merge pull request #1014 from BradLewis/fix/slicing-multipointers
Correct resolved types when slicing multi-pointers
-rw-r--r--src/server/analysis.odin4
-rw-r--r--tests/hover_test.odin28
2 files changed, 31 insertions, 1 deletions
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() {
@@ -4215,6 +4215,32 @@ ast_hover_multi_pointer_slice_range :: proc(t: ^testing.T) {
}
@(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 {
main = `package test