aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin@Daniels-MacBook-Air.local>2023-06-18 12:39:21 +0200
committerDaniel Gavin <danielgavin@Daniels-MacBook-Air.local>2023-06-18 12:39:21 +0200
commitaa191c9a55cec48025dbc125be4bd51d5a7545b0 (patch)
treedaa71f05aab10d92a81588b4922a9fc8b60fa527
parentb36ed688de204602303f40bab29359d3e984c9ed (diff)
Make sure that sliced expressions return slices.
-rwxr-xr-xbuild.sh23
-rw-r--r--src/server/analysis.odin31
-rw-r--r--tests/hover_test.odin14
3 files changed, 66 insertions, 2 deletions
diff --git a/build.sh b/build.sh
index 4a20064..644d308 100755
--- a/build.sh
+++ b/build.sh
@@ -26,6 +26,21 @@ then
#exit 1
fi
fi
+if [[ $1 == "single_test" ]]
+then
+ #BUG in odin test, it makes the executable with the same name as a folder and gets confused.
+ cd tests
+
+ odin test ../tests -collection:shared=../src -test-name:$2
+
+ if ([ $? -ne 0 ])
+ then
+ echo "Test failed"
+ exit 1
+ fi
+
+ exit 0
+fi
if [[ $1 == "test" ]]
then
@@ -40,7 +55,13 @@ then
exit 1
fi
- cd ..
+ exit 0
+fi
+if [[ $1 == "debug" ]]
+then
+ odin build src/ -collection:shared=src -out:ols -debug
+ exit 0
fi
+
odin build src/ -collection:shared=src -out:ols -o:speed
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 5d9fbe6..a312d6a 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1244,7 +1244,7 @@ internal_resolve_type_expression :: proc(
case ^Paren_Expr:
return internal_resolve_type_expression(ast_context, v.expr)
case ^Slice_Expr:
- return internal_resolve_type_expression(ast_context, v.expr)
+ return resolve_slice_expression(ast_context, v)
case ^Tag_Expr:
return internal_resolve_type_expression(ast_context, v.expr)
case ^Helper_Type:
@@ -1983,6 +1983,35 @@ expand_struct_usings :: proc(
return {names = names[:], types = types[:], ranges = ranges[:]}
}
+resolve_slice_expression :: proc(
+ ast_context: ^AstContext,
+ slice_expr: ^ast.Slice_Expr,
+) -> (
+ symbol: Symbol,
+ ok: bool,
+) {
+ symbol = resolve_type_expression(ast_context, slice_expr.expr) or_return
+
+ expr: ^ast.Expr
+
+ #partial switch v in symbol.value {
+ case SymbolSliceValue:
+ expr = v.expr
+ case SymbolFixedArrayValue:
+ expr = v.expr
+ case SymbolDynamicArrayValue:
+ expr = v.expr
+ case:
+ return {}, false
+ }
+
+ symbol.value = SymbolSliceValue {
+ expr = expr,
+ }
+
+ return symbol, true
+}
+
resolve_comp_literal :: proc(
ast_context: ^AstContext,
position_context: ^DocumentPositionContext,
diff --git a/tests/hover_test.odin b/tests/hover_test.odin
index 910f0be..a21ca70 100644
--- a/tests/hover_test.odin
+++ b/tests/hover_test.odin
@@ -156,3 +156,17 @@ ast_hover_same_name_in_selector_and_field :: proc(t: ^testing.T) {
test.expect_hover(t, &source, "Color.color: int")
}
+
+@(test)
+zzast_hover_on_sliced_result :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+ f :: proc() {
+ buf: [420]byte
+ slic{*}e := buf[2:20]
+ }
+ `,
+ }
+
+ test.expect_hover(t, &source, "test.slice: []byte")
+}