authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-24 20:29:13+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-24 21:31:02+03:00
log1d0b729f28dd5f9341c4f4fe8ab4b25592e6834a
tree112761c019acd159cb37429329f15332916c6d04
parentcd1833044ab7505bc101c85f59889bd3ea3fac80

Sema: fix crash on slice of non-array type

Closes #12621

2 files changed, 11 insertions(+), 1 deletions(-)

src/Sema.zig+2-1
...@@ -26139,11 +26139,12 @@ fn analyzeSlice(...@@ -26139,11 +26139,12 @@ fn analyzeSlice(
26139 var array_ty = ptr_ptr_child_ty;26139 var array_ty = ptr_ptr_child_ty;
26140 var slice_ty = ptr_ptr_ty;26140 var slice_ty = ptr_ptr_ty;
26141 var ptr_or_slice = ptr_ptr;26141 var ptr_or_slice = ptr_ptr;
26142 var elem_ty = ptr_ptr_child_ty.childType();26142 var elem_ty: Type = undefined;
26143 var ptr_sentinel: ?Value = null;26143 var ptr_sentinel: ?Value = null;
26144 switch (ptr_ptr_child_ty.zigTypeTag()) {26144 switch (ptr_ptr_child_ty.zigTypeTag()) {
26145 .Array => {26145 .Array => {
26146 ptr_sentinel = ptr_ptr_child_ty.sentinel();26146 ptr_sentinel = ptr_ptr_child_ty.sentinel();
26147 elem_ty = ptr_ptr_child_ty.childType();
26147 },26148 },
26148 .Pointer => switch (ptr_ptr_child_ty.ptrSize()) {26149 .Pointer => switch (ptr_ptr_child_ty.ptrSize()) {
26149 .One => {26150 .One => {
test/cases/compile_errors/slice_of_non_array_type.zig created+9
...@@ -0,0 +1,9 @@
1comptime {
2 _ = 1[0..];
3}
4
5// error
6// backend=stage2
7// target=native
8//
9// :2:10: error: slice of non-array type 'comptime_int'