Commit 1d0b729f28

Veikka Tuominen <git@vexu.eu>
2022-08-24 19:29:13
Sema: fix crash on slice of non-array type
Closes #12621
1 parent cd18330
Changed files (2)
src
test
cases
src/Sema.zig
@@ -26139,11 +26139,12 @@ fn analyzeSlice(
     var array_ty = ptr_ptr_child_ty;
     var slice_ty = ptr_ptr_ty;
     var ptr_or_slice = ptr_ptr;
-    var elem_ty = ptr_ptr_child_ty.childType();
+    var elem_ty: Type = undefined;
     var ptr_sentinel: ?Value = null;
     switch (ptr_ptr_child_ty.zigTypeTag()) {
         .Array => {
             ptr_sentinel = ptr_ptr_child_ty.sentinel();
+            elem_ty = ptr_ptr_child_ty.childType();
         },
         .Pointer => switch (ptr_ptr_child_ty.ptrSize()) {
             .One => {
test/cases/compile_errors/slice_of_non_array_type.zig
@@ -0,0 +1,9 @@
+comptime {
+    _ = 1[0..];
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :2:10: error: slice of non-array type 'comptime_int'