| ... | ... | @@ -18208,7 +18208,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18208 | 18208 | return sema.analyzeDeclVal(block, src, new_decl_index); |
| 18209 | 18209 | }, |
| 18210 | 18210 | .Fn => { |
| 18211 | | const struct_val = union_val.val.castTag(.aggregate).?.data; |
| 18211 | const struct_val: []const Value = union_val.val.castTag(.aggregate).?.data; |
| 18212 | 18212 | // TODO use reflection instead of magic numbers here |
| 18213 | 18213 | // calling_convention: CallingConvention, |
| 18214 | 18214 | const cc = struct_val[0].toEnum(std.builtin.CallingConvention); |
| ... | ... | @@ -18242,12 +18242,17 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18242 | 18242 | break :alignment alignment; |
| 18243 | 18243 | } |
| 18244 | 18244 | }; |
| 18245 | const return_type = return_type_val.optionalValue() orelse |
| 18246 | return sema.fail(block, src, "Type.Fn.return_type must be non-null for @Type", .{}); |
| 18247 | |
| 18245 | 18248 | var buf: Value.ToTypeBuffer = undefined; |
| 18246 | 18249 | |
| 18247 | 18250 | const args_slice_val = args_val.castTag(.slice).?.data; |
| 18248 | 18251 | const args_len = try sema.usizeCast(block, src, args_slice_val.len.toUnsignedInt(mod.getTarget())); |
| 18249 | | var param_types = try sema.arena.alloc(Type, args_len); |
| 18250 | | var comptime_params = try sema.arena.alloc(bool, args_len); |
| 18252 | |
| 18253 | const param_types = try sema.arena.alloc(Type, args_len); |
| 18254 | const comptime_params = try sema.arena.alloc(bool, args_len); |
| 18255 | |
| 18251 | 18256 | var noalias_bits: u32 = 0; |
| 18252 | 18257 | var i: usize = 0; |
| 18253 | 18258 | while (i < args_len) : (i += 1) { |
| ... | ... | @@ -18275,11 +18280,9 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18275 | 18280 | return sema.fail(block, src, "Type.Fn.Param.arg_type must be non-null for @Type", .{}); |
| 18276 | 18281 | |
| 18277 | 18282 | param_types[i] = try param_type.toType(&buf).copy(sema.arena); |
| 18283 | comptime_params[i] = false; |
| 18278 | 18284 | } |
| 18279 | 18285 | |
| 18280 | | const return_type = return_type_val.optionalValue() orelse |
| 18281 | | return sema.fail(block, src, "Type.Fn.return_type must be non-null for @Type", .{}); |
| 18282 | | |
| 18283 | 18286 | var fn_info = Type.Payload.Function.Data{ |
| 18284 | 18287 | .param_types = param_types, |
| 18285 | 18288 | .comptime_params = comptime_params.ptr, |
| ... | ... | @@ -24075,20 +24078,23 @@ fn coerceExtra( |
| 24075 | 24078 | }, |
| 24076 | 24079 | else => {}, |
| 24077 | 24080 | }, |
| 24078 | | .Slice => { |
| 24079 | | // pointer to tuple to slice |
| 24080 | | if (inst_ty.isSinglePointer() and inst_ty.childType().isTuple() and dest_info.size == .Slice and |
| 24081 | | sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) |
| 24082 | | { |
| 24083 | | return sema.coerceTupleToSlicePtrs(block, dest_ty, dest_ty_src, inst, inst_src); |
| 24081 | .Slice => to_slice: { |
| 24082 | if (inst_ty.zigTypeTag() == .Array) { |
| 24083 | return sema.fail( |
| 24084 | block, |
| 24085 | inst_src, |
| 24086 | "array literal requires address-of operator (&) to coerce to slice type '{}'", |
| 24087 | .{dest_ty.fmt(sema.mod)}, |
| 24088 | ); |
| 24084 | 24089 | } |
| 24085 | 24090 | |
| 24091 | if (!inst_ty.isSinglePointer()) break :to_slice; |
| 24092 | const inst_child_ty = inst_ty.childType(); |
| 24093 | if (!inst_child_ty.isTuple()) break :to_slice; |
| 24094 | |
| 24086 | 24095 | // empty tuple to zero-length slice |
| 24087 | 24096 | // note that this allows coercing to a mutable slice. |
| 24088 | | if (inst_ty.isSinglePointer() and |
| 24089 | | inst_ty.childType().tag() == .empty_struct_literal and |
| 24090 | | dest_info.size == .Slice) |
| 24091 | | { |
| 24097 | if (inst_child_ty.tupleFields().types.len == 0) { |
| 24092 | 24098 | const slice_val = try Value.Tag.slice.create(sema.arena, .{ |
| 24093 | 24099 | .ptr = Value.undef, |
| 24094 | 24100 | .len = Value.zero, |
| ... | ... | @@ -24096,14 +24102,17 @@ fn coerceExtra( |
| 24096 | 24102 | return sema.addConstant(dest_ty, slice_val); |
| 24097 | 24103 | } |
| 24098 | 24104 | |
| 24099 | | if (inst_ty.zigTypeTag() == .Array) { |
| 24100 | | return sema.fail( |
| 24101 | | block, |
| 24102 | | inst_src, |
| 24103 | | "array literal requires address-of operator (&) to coerce to slice type '{}'", |
| 24104 | | .{dest_ty.fmt(sema.mod)}, |
| 24105 | | ); |
| 24105 | // pointer to tuple to slice |
| 24106 | if (dest_info.mutable) { |
| 24107 | const err_msg = err_msg: { |
| 24108 | const err_msg = try sema.errMsg(block, inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(sema.mod)}); |
| 24109 | errdefer err_msg.deinit(sema.gpa); |
| 24110 | try sema.errNote(block, dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{}); |
| 24111 | break :err_msg err_msg; |
| 24112 | }; |
| 24113 | return sema.failWithOwnedErrorMsg(err_msg); |
| 24106 | 24114 | } |
| 24115 | return sema.coerceTupleToSlicePtrs(block, dest_ty, dest_ty_src, inst, inst_src); |
| 24107 | 24116 | }, |
| 24108 | 24117 | .Many => p: { |
| 24109 | 24118 | if (!inst_ty.isSlice()) break :p; |