| ... | @@ -3628,6 +3628,10 @@ fn zirAllocExtended( | ... | @@ -3628,6 +3628,10 @@ fn zirAllocExtended( |
| 3628 | } | 3628 | } |
| 3629 | } | 3629 | } |
| 3630 | | 3630 | |
| | 3631 | if (small.has_type and try var_ty.comptimeOnlySema(pt)) { |
| | 3632 | return sema.analyzeComptimeAlloc(block, var_ty, alignment); |
| | 3633 | } |
| | 3634 | |
| 3631 | if (small.has_type) { | 3635 | if (small.has_type) { |
| 3632 | if (!small.is_const) { | 3636 | if (!small.is_const) { |
| 3633 | try sema.validateVarType(block, ty_src, var_ty, false); | 3637 | try sema.validateVarType(block, ty_src, var_ty, false); |
| ... | @@ -4075,7 +4079,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -4075,7 +4079,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 4075 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); | 4079 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 4076 | | 4080 | |
| 4077 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 4081 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 4078 | if (block.is_comptime) { | 4082 | if (block.is_comptime or try var_ty.comptimeOnlySema(pt)) { |
| 4079 | return sema.analyzeComptimeAlloc(block, var_ty, .none); | 4083 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| 4080 | } | 4084 | } |
| 4081 | if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) { | 4085 | if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) { |
| ... | @@ -30675,6 +30679,18 @@ fn coerceExtra( | ... | @@ -30675,6 +30679,18 @@ fn coerceExtra( |
| 30675 | else => {}, | 30679 | else => {}, |
| 30676 | } | 30680 | } |
| 30677 | | 30681 | |
| | 30682 | const can_coerce_to = switch (dest_ty.zigTypeTag(zcu)) { |
| | 30683 | .noreturn, .@"opaque" => false, |
| | 30684 | else => true, |
| | 30685 | }; |
| | 30686 | |
| | 30687 | if (can_coerce_to) { |
| | 30688 | // undefined to anything. We do this after the big switch above so that |
| | 30689 | // special logic has a chance to run first, such as `*[N]T` to `[]T` which |
| | 30690 | // should initialize the length field of the slice. |
| | 30691 | if (maybe_inst_val) |val| if (val.toIntern() == .undef) return pt.undefRef(dest_ty); |
| | 30692 | } |
| | 30693 | |
| 30678 | if (!opts.report_err) return error.NotCoercible; | 30694 | if (!opts.report_err) return error.NotCoercible; |
| 30679 | | 30695 | |
| 30680 | if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .noreturn) { | 30696 | if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .noreturn) { |
| ... | @@ -30692,15 +30708,14 @@ fn coerceExtra( | ... | @@ -30692,15 +30708,14 @@ fn coerceExtra( |
| 30692 | return sema.failWithOwnedErrorMsg(block, msg); | 30708 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30693 | } | 30709 | } |
| 30694 | | 30710 | |
| 30695 | // undefined to anything. We do this after the big switch above so that | | |
| 30696 | // special logic has a chance to run first, such as `*[N]T` to `[]T` which | | |
| 30697 | // should initialize the length field of the slice. | | |
| 30698 | if (maybe_inst_val) |val| if (val.toIntern() == .undef) return pt.undefRef(dest_ty); | | |
| 30699 | | | |
| 30700 | const msg = msg: { | 30711 | const msg = msg: { |
| 30701 | const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(pt), inst_ty.fmt(pt) }); | 30712 | const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(pt), inst_ty.fmt(pt) }); |
| 30702 | errdefer msg.destroy(sema.gpa); | 30713 | errdefer msg.destroy(sema.gpa); |
| 30703 | | 30714 | |
| | 30715 | if (!can_coerce_to) { |
| | 30716 | try sema.errNote(inst_src, msg, "cannot coerce to '{}'", .{dest_ty.fmt(pt)}); |
| | 30717 | } |
| | 30718 | |
| 30704 | // E!T to T | 30719 | // E!T to T |
| 30705 | if (inst_ty.zigTypeTag(zcu) == .error_union and | 30720 | if (inst_ty.zigTypeTag(zcu) == .error_union and |
| 30706 | (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src, maybe_inst_val)) == .ok) | 30721 | (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src, maybe_inst_val)) == .ok) |
| ... | @@ -31927,6 +31942,17 @@ fn storePtr2( | ... | @@ -31927,6 +31942,17 @@ fn storePtr2( |
| 31927 | } else break :rs ptr_src; | 31942 | } else break :rs ptr_src; |
| 31928 | } else ptr_src; | 31943 | } else ptr_src; |
| 31929 | | 31944 | |
| | 31945 | // We're performing the store at runtime; as such, we need to make sure the pointee type |
| | 31946 | // is not comptime-only. We can hit this case with a `@ptrFromInt` pointer. |
| | 31947 | if (try elem_ty.comptimeOnlySema(pt)) { |
| | 31948 | return sema.failWithOwnedErrorMsg(block, msg: { |
| | 31949 | const msg = try sema.errMsg(src, "cannot store comptime-only type '{}' at runtime", .{elem_ty.fmt(pt)}); |
| | 31950 | errdefer msg.destroy(sema.gpa); |
| | 31951 | try sema.errNote(ptr_src, msg, "operation is runtime due to this pointer", .{}); |
| | 31952 | break :msg msg; |
| | 31953 | }); |
| | 31954 | } |
| | 31955 | |
| 31930 | // We do this after the possible comptime store above, for the case of field_ptr stores | 31956 | // We do this after the possible comptime store above, for the case of field_ptr stores |
| 31931 | // to unions because we want the comptime tag to be set, even if the field type is void. | 31957 | // to unions because we want the comptime tag to be set, even if the field type is void. |
| 31932 | if ((try sema.typeHasOnePossibleValue(elem_ty)) != null) { | 31958 | if ((try sema.typeHasOnePossibleValue(elem_ty)) != null) { |