| ... | @@ -4288,29 +4288,42 @@ fn zirValidateArrayInit( | ... | @@ -4288,29 +4288,42 @@ fn zirValidateArrayInit( |
| 4288 | const array_ty = sema.typeOf(array_ptr).childType(); | 4288 | const array_ty = sema.typeOf(array_ptr).childType(); |
| 4289 | const array_len = array_ty.arrayLen(); | 4289 | const array_len = array_ty.arrayLen(); |
| 4290 | | 4290 | |
| 4291 | if (instrs.len != array_len and array_ty.isTuple()) { | 4291 | if (instrs.len != array_len) switch (array_ty.zigTypeTag()) { |
| 4292 | const struct_obj = array_ty.castTag(.tuple).?.data; | 4292 | .Struct => { |
| 4293 | var root_msg: ?*Module.ErrorMsg = null; | 4293 | const struct_obj = array_ty.castTag(.tuple).?.data; |
| 4294 | errdefer if (root_msg) |msg| msg.destroy(sema.gpa); | 4294 | var root_msg: ?*Module.ErrorMsg = null; |
| | 4295 | errdefer if (root_msg) |msg| msg.destroy(sema.gpa); |
| 4295 | | 4296 | |
| 4296 | for (struct_obj.values) |default_val, i| { | 4297 | for (struct_obj.values) |default_val, i| { |
| 4297 | if (i < instrs.len) continue; | 4298 | if (i < instrs.len) continue; |
| 4298 | | 4299 | |
| 4299 | if (default_val.tag() == .unreachable_value) { | 4300 | if (default_val.tag() == .unreachable_value) { |
| 4300 | const template = "missing tuple field with index {d}"; | 4301 | const template = "missing tuple field with index {d}"; |
| 4301 | if (root_msg) |msg| { | 4302 | if (root_msg) |msg| { |
| 4302 | try sema.errNote(block, init_src, msg, template, .{i}); | 4303 | try sema.errNote(block, init_src, msg, template, .{i}); |
| 4303 | } else { | 4304 | } else { |
| 4304 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 4305 | root_msg = try sema.errMsg(block, init_src, template, .{i}); |
| | 4306 | } |
| 4305 | } | 4307 | } |
| 4306 | } | 4308 | } |
| 4307 | } | | |
| 4308 | | 4309 | |
| 4309 | if (root_msg) |msg| { | 4310 | if (root_msg) |msg| { |
| 4310 | root_msg = null; | 4311 | root_msg = null; |
| 4311 | return sema.failWithOwnedErrorMsg(msg); | 4312 | return sema.failWithOwnedErrorMsg(msg); |
| 4312 | } | 4313 | } |
| 4313 | } | 4314 | }, |
| | 4315 | .Array => { |
| | 4316 | return sema.fail(block, init_src, "expected {d} array elements; found {d}", .{ |
| | 4317 | array_len, instrs.len, |
| | 4318 | }); |
| | 4319 | }, |
| | 4320 | .Vector => { |
| | 4321 | return sema.fail(block, init_src, "expected {d} vector elements; found {d}", .{ |
| | 4322 | array_len, instrs.len, |
| | 4323 | }); |
| | 4324 | }, |
| | 4325 | else => unreachable, |
| | 4326 | }; |
| 4314 | | 4327 | |
| 4315 | if ((is_comptime or block.is_comptime) and | 4328 | if ((is_comptime or block.is_comptime) and |
| 4316 | (try sema.resolveDefinedValue(block, init_src, array_ptr)) != null) | 4329 | (try sema.resolveDefinedValue(block, init_src, array_ptr)) != null) |