| ... | @@ -3875,9 +3875,15 @@ fn zirValidateArrayInit( | ... | @@ -3875,9 +3875,15 @@ fn zirValidateArrayInit( |
| 3875 | const array_len = array_ty.arrayLen(); | 3875 | const array_len = array_ty.arrayLen(); |
| 3876 | | 3876 | |
| 3877 | if (instrs.len != array_len) { | 3877 | if (instrs.len != array_len) { |
| 3878 | return sema.fail(block, init_src, "expected {d} array elements; found {d}", .{ | 3878 | if (array_ty.zigTypeTag() == .Array) { |
| 3879 | array_len, instrs.len, | 3879 | return sema.fail(block, init_src, "expected {d} array elements; found {d}", .{ |
| 3880 | }); | 3880 | array_len, instrs.len, |
| | 3881 | }); |
| | 3882 | } else { |
| | 3883 | return sema.fail(block, init_src, "expected {d} vector elements; found {d}", .{ |
| | 3884 | array_len, instrs.len, |
| | 3885 | }); |
| | 3886 | } |
| 3881 | } | 3887 | } |
| 3882 | | 3888 | |
| 3883 | if ((is_comptime or block.is_comptime) and | 3889 | if ((is_comptime or block.is_comptime) and |
| ... | @@ -14265,7 +14271,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -14265,7 +14271,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 14265 | | 14271 | |
| 14266 | switch (obj_ty.zigTypeTag()) { | 14272 | switch (obj_ty.zigTypeTag()) { |
| 14267 | .Struct => return sema.structInitEmpty(block, obj_ty, src, src), | 14273 | .Struct => return sema.structInitEmpty(block, obj_ty, src, src), |
| 14268 | .Array => return arrayInitEmpty(sema, obj_ty), | 14274 | .Array, .Vector => return sema.arrayInitEmpty(block, src, obj_ty), |
| 14269 | .Void => return sema.addConstant(obj_ty, Value.void), | 14275 | .Void => return sema.addConstant(obj_ty, Value.void), |
| 14270 | else => return sema.failWithArrayInitNotSupported(block, src, obj_ty), | 14276 | else => return sema.failWithArrayInitNotSupported(block, src, obj_ty), |
| 14271 | } | 14277 | } |
| ... | @@ -14290,7 +14296,15 @@ fn structInitEmpty( | ... | @@ -14290,7 +14296,15 @@ fn structInitEmpty( |
| 14290 | return sema.finishStructInit(block, init_src, dest_src, field_inits, struct_ty, false); | 14296 | return sema.finishStructInit(block, init_src, dest_src, field_inits, struct_ty, false); |
| 14291 | } | 14297 | } |
| 14292 | | 14298 | |
| 14293 | fn arrayInitEmpty(sema: *Sema, obj_ty: Type) CompileError!Air.Inst.Ref { | 14299 | fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) CompileError!Air.Inst.Ref { |
| | 14300 | const arr_len = obj_ty.arrayLen(); |
| | 14301 | if (arr_len != 0) { |
| | 14302 | if (obj_ty.zigTypeTag() == .Array) { |
| | 14303 | return sema.fail(block, src, "expected {d} array elements; found 0", .{arr_len}); |
| | 14304 | } else { |
| | 14305 | return sema.fail(block, src, "expected {d} vector elements; found 0", .{arr_len}); |
| | 14306 | } |
| | 14307 | } |
| 14294 | if (obj_ty.sentinel()) |sentinel| { | 14308 | if (obj_ty.sentinel()) |sentinel| { |
| 14295 | const val = try Value.Tag.empty_array_sentinel.create(sema.arena, sentinel); | 14309 | const val = try Value.Tag.empty_array_sentinel.create(sema.arena, sentinel); |
| 14296 | return sema.addConstant(obj_ty, val); | 14310 | return sema.addConstant(obj_ty, val); |
| ... | @@ -20978,7 +20992,7 @@ fn coerceExtra( | ... | @@ -20978,7 +20992,7 @@ fn coerceExtra( |
| 20978 | .Vector => return sema.coerceArrayLike(block, dest_ty, dest_ty_src, inst, inst_src), | 20992 | .Vector => return sema.coerceArrayLike(block, dest_ty, dest_ty_src, inst, inst_src), |
| 20979 | .Struct => { | 20993 | .Struct => { |
| 20980 | if (inst == .empty_struct) { | 20994 | if (inst == .empty_struct) { |
| 20981 | return arrayInitEmpty(sema, dest_ty); | 20995 | return sema.arrayInitEmpty(block, inst_src, dest_ty); |
| 20982 | } | 20996 | } |
| 20983 | if (inst_ty.isTuple()) { | 20997 | if (inst_ty.isTuple()) { |
| 20984 | return sema.coerceTupleToArray(block, dest_ty, dest_ty_src, inst, inst_src); | 20998 | return sema.coerceTupleToArray(block, dest_ty, dest_ty_src, inst, inst_src); |