| ... | @@ -712,6 +712,7 @@ fn analyzeBodyInner( | ... | @@ -712,6 +712,7 @@ fn analyzeBodyInner( |
| 712 | .vector_type => try sema.zirVectorType(block, inst), | 712 | .vector_type => try sema.zirVectorType(block, inst), |
| 713 | .as => try sema.zirAs(block, inst), | 713 | .as => try sema.zirAs(block, inst), |
| 714 | .as_node => try sema.zirAsNode(block, inst), | 714 | .as_node => try sema.zirAsNode(block, inst), |
| | 715 | .as_shift_operand => try sema.zirAsShiftOperand(block, inst), |
| 715 | .bit_and => try sema.zirBitwise(block, inst, .bit_and), | 716 | .bit_and => try sema.zirBitwise(block, inst, .bit_and), |
| 716 | .bit_not => try sema.zirBitNot(block, inst), | 717 | .bit_not => try sema.zirBitNot(block, inst), |
| 717 | .bit_or => try sema.zirBitwise(block, inst, .bit_or), | 718 | .bit_or => try sema.zirBitwise(block, inst, .bit_or), |
| ... | @@ -848,7 +849,6 @@ fn analyzeBodyInner( | ... | @@ -848,7 +849,6 @@ fn analyzeBodyInner( |
| 848 | .mul_add => try sema.zirMulAdd(block, inst), | 849 | .mul_add => try sema.zirMulAdd(block, inst), |
| 849 | .builtin_call => try sema.zirBuiltinCall(block, inst), | 850 | .builtin_call => try sema.zirBuiltinCall(block, inst), |
| 850 | .field_parent_ptr => try sema.zirFieldParentPtr(block, inst), | 851 | .field_parent_ptr => try sema.zirFieldParentPtr(block, inst), |
| 851 | .builtin_async_call => try sema.zirBuiltinAsyncCall(block, inst), | | |
| 852 | .@"resume" => try sema.zirResume(block, inst), | 852 | .@"resume" => try sema.zirResume(block, inst), |
| 853 | .@"await" => try sema.zirAwait(block, inst), | 853 | .@"await" => try sema.zirAwait(block, inst), |
| 854 | .array_base_ptr => try sema.zirArrayBasePtr(block, inst), | 854 | .array_base_ptr => try sema.zirArrayBasePtr(block, inst), |
| ... | @@ -956,6 +956,7 @@ fn analyzeBodyInner( | ... | @@ -956,6 +956,7 @@ fn analyzeBodyInner( |
| 956 | .error_to_int => try sema.zirErrorToInt( block, extended), | 956 | .error_to_int => try sema.zirErrorToInt( block, extended), |
| 957 | .int_to_error => try sema.zirIntToError( block, extended), | 957 | .int_to_error => try sema.zirIntToError( block, extended), |
| 958 | .reify => try sema.zirReify( block, extended, inst), | 958 | .reify => try sema.zirReify( block, extended, inst), |
| | 959 | .builtin_async_call => try sema.zirBuiltinAsyncCall( block, extended), |
| 959 | // zig fmt: on | 960 | // zig fmt: on |
| 960 | .fence => { | 961 | .fence => { |
| 961 | try sema.zirFence(block, extended); | 962 | try sema.zirFence(block, extended); |
| ... | @@ -8257,7 +8258,7 @@ fn zirAs(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst | ... | @@ -8257,7 +8258,7 @@ fn zirAs(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst |
| 8257 | defer tracy.end(); | 8258 | defer tracy.end(); |
| 8258 | | 8259 | |
| 8259 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; | 8260 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; |
| 8260 | return sema.analyzeAs(block, sema.src, bin_inst.lhs, bin_inst.rhs); | 8261 | return sema.analyzeAs(block, sema.src, bin_inst.lhs, bin_inst.rhs, false); |
| 8261 | } | 8262 | } |
| 8262 | | 8263 | |
| 8263 | fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8264 | fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -8267,7 +8268,17 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -8267,7 +8268,17 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 8267 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8268 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8268 | const src = inst_data.src(); | 8269 | const src = inst_data.src(); |
| 8269 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; | 8270 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; |
| 8270 | return sema.analyzeAs(block, src, extra.dest_type, extra.operand); | 8271 | return sema.analyzeAs(block, src, extra.dest_type, extra.operand, false); |
| | 8272 | } |
| | 8273 | |
| | 8274 | fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| | 8275 | const tracy = trace(@src()); |
| | 8276 | defer tracy.end(); |
| | 8277 | |
| | 8278 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| | 8279 | const src = inst_data.src(); |
| | 8280 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; |
| | 8281 | return sema.analyzeAs(block, src, extra.dest_type, extra.operand, true); |
| 8271 | } | 8282 | } |
| 8272 | | 8283 | |
| 8273 | fn analyzeAs( | 8284 | fn analyzeAs( |
| ... | @@ -8276,6 +8287,7 @@ fn analyzeAs( | ... | @@ -8276,6 +8287,7 @@ fn analyzeAs( |
| 8276 | src: LazySrcLoc, | 8287 | src: LazySrcLoc, |
| 8277 | zir_dest_type: Zir.Inst.Ref, | 8288 | zir_dest_type: Zir.Inst.Ref, |
| 8278 | zir_operand: Zir.Inst.Ref, | 8289 | zir_operand: Zir.Inst.Ref, |
| | 8290 | no_cast_to_comptime_int: bool, |
| 8279 | ) CompileError!Air.Inst.Ref { | 8291 | ) CompileError!Air.Inst.Ref { |
| 8280 | const is_ret = if (Zir.refToIndex(zir_dest_type)) |ptr_index| | 8292 | const is_ret = if (Zir.refToIndex(zir_dest_type)) |ptr_index| |
| 8281 | sema.code.instructions.items(.tag)[ptr_index] == .ret_type | 8293 | sema.code.instructions.items(.tag)[ptr_index] == .ret_type |
| ... | @@ -8287,7 +8299,7 @@ fn analyzeAs( | ... | @@ -8287,7 +8299,7 @@ fn analyzeAs( |
| 8287 | if (dest_ty.zigTypeTag() == .NoReturn) { | 8299 | if (dest_ty.zigTypeTag() == .NoReturn) { |
| 8288 | return sema.fail(block, src, "cannot cast to noreturn", .{}); | 8300 | return sema.fail(block, src, "cannot cast to noreturn", .{}); |
| 8289 | } | 8301 | } |
| 8290 | return sema.coerceExtra(block, dest_ty, operand, src, true, is_ret) catch |err| switch (err) { | 8302 | return sema.coerceExtra(block, dest_ty, operand, src, .{ .is_ret = is_ret, .no_cast_to_comptime_int = no_cast_to_comptime_int }) catch |err| switch (err) { |
| 8291 | error.NotCoercible => unreachable, | 8303 | error.NotCoercible => unreachable, |
| 8292 | else => |e| return e, | 8304 | else => |e| return e, |
| 8293 | }; | 8305 | }; |
| ... | @@ -10491,7 +10503,12 @@ fn zirShl( | ... | @@ -10491,7 +10503,12 @@ fn zirShl( |
| 10491 | | 10503 | |
| 10492 | const runtime_src = if (maybe_lhs_val) |lhs_val| rs: { | 10504 | const runtime_src = if (maybe_lhs_val) |lhs_val| rs: { |
| 10493 | if (lhs_val.isUndef()) return sema.addConstUndef(lhs_ty); | 10505 | if (lhs_val.isUndef()) return sema.addConstUndef(lhs_ty); |
| 10494 | const rhs_val = maybe_rhs_val orelse break :rs rhs_src; | 10506 | const rhs_val = maybe_rhs_val orelse { |
| | 10507 | if (scalar_ty.zigTypeTag() == .ComptimeInt) { |
| | 10508 | return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be a comptime known", .{}); |
| | 10509 | } |
| | 10510 | break :rs rhs_src; |
| | 10511 | }; |
| 10495 | | 10512 | |
| 10496 | const val = switch (air_tag) { | 10513 | const val = switch (air_tag) { |
| 10497 | .shl_exact => val: { | 10514 | .shl_exact => val: { |
| ... | @@ -10615,7 +10632,10 @@ fn zirShr( | ... | @@ -10615,7 +10632,10 @@ fn zirShr( |
| 10615 | const target = sema.mod.getTarget(); | 10632 | const target = sema.mod.getTarget(); |
| 10616 | const scalar_ty = lhs_ty.scalarType(); | 10633 | const scalar_ty = lhs_ty.scalarType(); |
| 10617 | | 10634 | |
| 10618 | const runtime_src = if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| rs: { | 10635 | const maybe_lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs); |
| | 10636 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs); |
| | 10637 | |
| | 10638 | const runtime_src = if (maybe_rhs_val) |rhs_val| rs: { |
| 10619 | if (rhs_val.isUndef()) { | 10639 | if (rhs_val.isUndef()) { |
| 10620 | return sema.addConstUndef(lhs_ty); | 10640 | return sema.addConstUndef(lhs_ty); |
| 10621 | } | 10641 | } |
| ... | @@ -10647,7 +10667,7 @@ fn zirShr( | ... | @@ -10647,7 +10667,7 @@ fn zirShr( |
| 10647 | }); | 10667 | }); |
| 10648 | } | 10668 | } |
| 10649 | } | 10669 | } |
| 10650 | if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| { | 10670 | if (maybe_lhs_val) |lhs_val| { |
| 10651 | if (lhs_val.isUndef()) { | 10671 | if (lhs_val.isUndef()) { |
| 10652 | return sema.addConstUndef(lhs_ty); | 10672 | return sema.addConstUndef(lhs_ty); |
| 10653 | } | 10673 | } |
| ... | @@ -10665,6 +10685,10 @@ fn zirShr( | ... | @@ -10665,6 +10685,10 @@ fn zirShr( |
| 10665 | } | 10685 | } |
| 10666 | } else rhs_src; | 10686 | } else rhs_src; |
| 10667 | | 10687 | |
| | 10688 | if (maybe_rhs_val == null and scalar_ty.zigTypeTag() == .ComptimeInt) { |
| | 10689 | return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be a comptime known", .{}); |
| | 10690 | } |
| | 10691 | |
| 10668 | try sema.requireRuntimeBlock(block, src, runtime_src); | 10692 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 10669 | const result = try block.addBinOp(air_tag, lhs, rhs); | 10693 | const result = try block.addBinOp(air_tag, lhs, rhs); |
| 10670 | if (block.wantSafety()) { | 10694 | if (block.wantSafety()) { |
| ... | @@ -15385,7 +15409,7 @@ fn analyzeRet( | ... | @@ -15385,7 +15409,7 @@ fn analyzeRet( |
| 15385 | if (sema.fn_ret_ty.zigTypeTag() == .ErrorUnion) { | 15409 | if (sema.fn_ret_ty.zigTypeTag() == .ErrorUnion) { |
| 15386 | try sema.addToInferredErrorSet(uncasted_operand); | 15410 | try sema.addToInferredErrorSet(uncasted_operand); |
| 15387 | } | 15411 | } |
| 15388 | const operand = sema.coerceExtra(block, sema.fn_ret_ty, uncasted_operand, src, true, true) catch |err| switch (err) { | 15412 | const operand = sema.coerceExtra(block, sema.fn_ret_ty, uncasted_operand, src, .{ .is_ret = true }) catch |err| switch (err) { |
| 15389 | error.NotCoercible => unreachable, | 15413 | error.NotCoercible => unreachable, |
| 15390 | else => |e| return e, | 15414 | else => |e| return e, |
| 15391 | }; | 15415 | }; |
| ... | @@ -19652,9 +19676,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -19652,9 +19676,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 19652 | }); | 19676 | }); |
| 19653 | } | 19677 | } |
| 19654 | | 19678 | |
| 19655 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 19679 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 19656 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 19680 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 19657 | const src = inst_data.src(); | 19681 | const src = LazySrcLoc.nodeOffset(extra.node); |
| 19658 | return sema.failWithUseOfAsync(block, src); | 19682 | return sema.failWithUseOfAsync(block, src); |
| 19659 | } | 19683 | } |
| 19660 | | 19684 | |
| ... | @@ -22542,7 +22566,7 @@ fn coerce( | ... | @@ -22542,7 +22566,7 @@ fn coerce( |
| 22542 | inst: Air.Inst.Ref, | 22566 | inst: Air.Inst.Ref, |
| 22543 | inst_src: LazySrcLoc, | 22567 | inst_src: LazySrcLoc, |
| 22544 | ) CompileError!Air.Inst.Ref { | 22568 | ) CompileError!Air.Inst.Ref { |
| 22545 | return sema.coerceExtra(block, dest_ty_unresolved, inst, inst_src, true, false) catch |err| switch (err) { | 22569 | return sema.coerceExtra(block, dest_ty_unresolved, inst, inst_src, .{}) catch |err| switch (err) { |
| 22546 | error.NotCoercible => unreachable, | 22570 | error.NotCoercible => unreachable, |
| 22547 | else => |e| return e, | 22571 | else => |e| return e, |
| 22548 | }; | 22572 | }; |
| ... | @@ -22554,14 +22578,22 @@ const CoersionError = CompileError || error{ | ... | @@ -22554,14 +22578,22 @@ const CoersionError = CompileError || error{ |
| 22554 | NotCoercible, | 22578 | NotCoercible, |
| 22555 | }; | 22579 | }; |
| 22556 | | 22580 | |
| | 22581 | const CoerceOpts = struct { |
| | 22582 | /// Should coerceExtra emit error messages. |
| | 22583 | report_err: bool = true, |
| | 22584 | /// Ignored if `report_err == false`. |
| | 22585 | is_ret: bool = false, |
| | 22586 | /// Should coercion to comptime_int ermit an error message. |
| | 22587 | no_cast_to_comptime_int: bool = false, |
| | 22588 | }; |
| | 22589 | |
| 22557 | fn coerceExtra( | 22590 | fn coerceExtra( |
| 22558 | sema: *Sema, | 22591 | sema: *Sema, |
| 22559 | block: *Block, | 22592 | block: *Block, |
| 22560 | dest_ty_unresolved: Type, | 22593 | dest_ty_unresolved: Type, |
| 22561 | inst: Air.Inst.Ref, | 22594 | inst: Air.Inst.Ref, |
| 22562 | inst_src: LazySrcLoc, | 22595 | inst_src: LazySrcLoc, |
| 22563 | report_err: bool, | 22596 | opts: CoerceOpts, |
| 22564 | is_ret: bool, | | |
| 22565 | ) CoersionError!Air.Inst.Ref { | 22597 | ) CoersionError!Air.Inst.Ref { |
| 22566 | switch (dest_ty_unresolved.tag()) { | 22598 | switch (dest_ty_unresolved.tag()) { |
| 22567 | .var_args_param => return sema.coerceVarArgParam(block, inst, inst_src), | 22599 | .var_args_param => return sema.coerceVarArgParam(block, inst, inst_src), |
| ... | @@ -22613,7 +22645,7 @@ fn coerceExtra( | ... | @@ -22613,7 +22645,7 @@ fn coerceExtra( |
| 22613 | | 22645 | |
| 22614 | // T to ?T | 22646 | // T to ?T |
| 22615 | const child_type = try dest_ty.optionalChildAlloc(sema.arena); | 22647 | const child_type = try dest_ty.optionalChildAlloc(sema.arena); |
| 22616 | const intermediate = sema.coerceExtra(block, child_type, inst, inst_src, false, is_ret) catch |err| switch (err) { | 22648 | const intermediate = sema.coerceExtra(block, child_type, inst, inst_src, .{ .report_err = false }) catch |err| switch (err) { |
| 22617 | error.NotCoercible => { | 22649 | error.NotCoercible => { |
| 22618 | if (in_memory_result == .no_match) { | 22650 | if (in_memory_result == .no_match) { |
| 22619 | // Try to give more useful notes | 22651 | // Try to give more useful notes |
| ... | @@ -22729,7 +22761,7 @@ fn coerceExtra( | ... | @@ -22729,7 +22761,7 @@ fn coerceExtra( |
| 22729 | return sema.addConstant(dest_ty, Value.@"null"); | 22761 | return sema.addConstant(dest_ty, Value.@"null"); |
| 22730 | }, | 22762 | }, |
| 22731 | .ComptimeInt => { | 22763 | .ComptimeInt => { |
| 22732 | const addr = sema.coerceExtra(block, Type.usize, inst, inst_src, false, is_ret) catch |err| switch (err) { | 22764 | const addr = sema.coerceExtra(block, Type.usize, inst, inst_src, .{ .report_err = false }) catch |err| switch (err) { |
| 22733 | error.NotCoercible => break :pointer, | 22765 | error.NotCoercible => break :pointer, |
| 22734 | else => |e| return e, | 22766 | else => |e| return e, |
| 22735 | }; | 22767 | }; |
| ... | @@ -22740,7 +22772,7 @@ fn coerceExtra( | ... | @@ -22740,7 +22772,7 @@ fn coerceExtra( |
| 22740 | .signed => Type.isize, | 22772 | .signed => Type.isize, |
| 22741 | .unsigned => Type.usize, | 22773 | .unsigned => Type.usize, |
| 22742 | }; | 22774 | }; |
| 22743 | const addr = sema.coerceExtra(block, ptr_size_ty, inst, inst_src, false, is_ret) catch |err| switch (err) { | 22775 | const addr = sema.coerceExtra(block, ptr_size_ty, inst, inst_src, .{ .report_err = false }) catch |err| switch (err) { |
| 22744 | error.NotCoercible => { | 22776 | error.NotCoercible => { |
| 22745 | // Try to give more useful notes | 22777 | // Try to give more useful notes |
| 22746 | in_memory_result = try sema.coerceInMemoryAllowed(block, ptr_size_ty, inst_ty, false, target, dest_ty_src, inst_src); | 22778 | in_memory_result = try sema.coerceInMemoryAllowed(block, ptr_size_ty, inst_ty, false, target, dest_ty_src, inst_src); |
| ... | @@ -22866,7 +22898,13 @@ fn coerceExtra( | ... | @@ -22866,7 +22898,13 @@ fn coerceExtra( |
| 22866 | }, | 22898 | }, |
| 22867 | .Int, .ComptimeInt => switch (inst_ty.zigTypeTag()) { | 22899 | .Int, .ComptimeInt => switch (inst_ty.zigTypeTag()) { |
| 22868 | .Float, .ComptimeFloat => float: { | 22900 | .Float, .ComptimeFloat => float: { |
| 22869 | const val = (try sema.resolveDefinedValue(block, inst_src, inst)) orelse break :float; | 22901 | const val = (try sema.resolveDefinedValue(block, inst_src, inst)) orelse { |
| | 22902 | if (dest_ty.zigTypeTag() == .ComptimeInt) { |
| | 22903 | if (!opts.report_err) return error.NotCoercible; |
| | 22904 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime known"); |
| | 22905 | } |
| | 22906 | break :float; |
| | 22907 | }; |
| 22870 | | 22908 | |
| 22871 | if (val.floatHasFraction()) { | 22909 | if (val.floatHasFraction()) { |
| 22872 | return sema.fail( | 22910 | return sema.fail( |
| ... | @@ -22883,11 +22921,16 @@ fn coerceExtra( | ... | @@ -22883,11 +22921,16 @@ fn coerceExtra( |
| 22883 | if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| { | 22921 | if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| { |
| 22884 | // comptime known integer to other number | 22922 | // comptime known integer to other number |
| 22885 | if (!(try sema.intFitsInType(block, inst_src, val, dest_ty, null))) { | 22923 | if (!(try sema.intFitsInType(block, inst_src, val, dest_ty, null))) { |
| 22886 | if (!report_err) return error.NotCoercible; | 22924 | if (!opts.report_err) return error.NotCoercible; |
| 22887 | return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(sema.mod), val.fmtValue(inst_ty, sema.mod) }); | 22925 | return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(sema.mod), val.fmtValue(inst_ty, sema.mod) }); |
| 22888 | } | 22926 | } |
| 22889 | return try sema.addConstant(dest_ty, val); | 22927 | return try sema.addConstant(dest_ty, val); |
| 22890 | } | 22928 | } |
| | 22929 | if (dest_ty.zigTypeTag() == .ComptimeInt) { |
| | 22930 | if (!opts.report_err) return error.NotCoercible; |
| | 22931 | if (opts.no_cast_to_comptime_int) return inst; |
| | 22932 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime known"); |
| | 22933 | } |
| 22891 | | 22934 | |
| 22892 | // integer widening | 22935 | // integer widening |
| 22893 | const dst_info = dest_ty.intInfo(target); | 22936 | const dst_info = dest_ty.intInfo(target); |
| ... | @@ -22924,6 +22967,7 @@ fn coerceExtra( | ... | @@ -22924,6 +22967,7 @@ fn coerceExtra( |
| 22924 | } | 22967 | } |
| 22925 | return try sema.addConstant(dest_ty, result_val); | 22968 | return try sema.addConstant(dest_ty, result_val); |
| 22926 | } else if (dest_ty.zigTypeTag() == .ComptimeFloat) { | 22969 | } else if (dest_ty.zigTypeTag() == .ComptimeFloat) { |
| | 22970 | if (!opts.report_err) return error.NotCoercible; |
| 22927 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime known"); | 22971 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime known"); |
| 22928 | } | 22972 | } |
| 22929 | | 22973 | |
| ... | @@ -22936,7 +22980,13 @@ fn coerceExtra( | ... | @@ -22936,7 +22980,13 @@ fn coerceExtra( |
| 22936 | } | 22980 | } |
| 22937 | }, | 22981 | }, |
| 22938 | .Int, .ComptimeInt => int: { | 22982 | .Int, .ComptimeInt => int: { |
| 22939 | const val = (try sema.resolveDefinedValue(block, inst_src, inst)) orelse break :int; | 22983 | const val = (try sema.resolveDefinedValue(block, inst_src, inst)) orelse { |
| | 22984 | if (dest_ty.zigTypeTag() == .ComptimeFloat) { |
| | 22985 | if (!opts.report_err) return error.NotCoercible; |
| | 22986 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime known"); |
| | 22987 | } |
| | 22988 | break :int; |
| | 22989 | }; |
| 22940 | const result_val = try val.intToFloat(sema.arena, inst_ty, dest_ty, target); | 22990 | const result_val = try val.intToFloat(sema.arena, inst_ty, dest_ty, target); |
| 22941 | // TODO implement this compile error | 22991 | // TODO implement this compile error |
| 22942 | //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty); | 22992 | //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty); |
| ... | @@ -23088,9 +23138,9 @@ fn coerceExtra( | ... | @@ -23088,9 +23138,9 @@ fn coerceExtra( |
| 23088 | return sema.addConstUndef(dest_ty); | 23138 | return sema.addConstUndef(dest_ty); |
| 23089 | } | 23139 | } |
| 23090 | | 23140 | |
| 23091 | if (!report_err) return error.NotCoercible; | 23141 | if (!opts.report_err) return error.NotCoercible; |
| 23092 | | 23142 | |
| 23093 | if (is_ret and dest_ty.zigTypeTag() == .NoReturn) { | 23143 | if (opts.is_ret and dest_ty.zigTypeTag() == .NoReturn) { |
| 23094 | const msg = msg: { | 23144 | const msg = msg: { |
| 23095 | const msg = try sema.errMsg(block, inst_src, "function declared 'noreturn' returns", .{}); | 23145 | const msg = try sema.errMsg(block, inst_src, "function declared 'noreturn' returns", .{}); |
| 23096 | errdefer msg.destroy(sema.gpa); | 23146 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -23127,7 +23177,7 @@ fn coerceExtra( | ... | @@ -23127,7 +23177,7 @@ fn coerceExtra( |
| 23127 | try in_memory_result.report(sema, block, inst_src, msg); | 23177 | try in_memory_result.report(sema, block, inst_src, msg); |
| 23128 | | 23178 | |
| 23129 | // Add notes about function return type | 23179 | // Add notes about function return type |
| 23130 | if (is_ret and sema.mod.test_functions.get(sema.func.?.owner_decl) == null) { | 23180 | if (opts.is_ret and sema.mod.test_functions.get(sema.func.?.owner_decl) == null) { |
| 23131 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; | 23181 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; |
| 23132 | const src_decl = sema.mod.declPtr(sema.func.?.owner_decl); | 23182 | const src_decl = sema.mod.declPtr(sema.func.?.owner_decl); |
| 23133 | if (inst_ty.isError() and !dest_ty.isError()) { | 23183 | if (inst_ty.isError() and !dest_ty.isError()) { |
| ... | @@ -24088,7 +24138,7 @@ fn storePtr2( | ... | @@ -24088,7 +24138,7 @@ fn storePtr2( |
| 24088 | // https://github.com/ziglang/zig/issues/11154 | 24138 | // https://github.com/ziglang/zig/issues/11154 |
| 24089 | if (sema.obtainBitCastedVectorPtr(ptr)) |vector_ptr| { | 24139 | if (sema.obtainBitCastedVectorPtr(ptr)) |vector_ptr| { |
| 24090 | const vector_ty = sema.typeOf(vector_ptr).childType(); | 24140 | const vector_ty = sema.typeOf(vector_ptr).childType(); |
| 24091 | const vector = sema.coerceExtra(block, vector_ty, uncasted_operand, operand_src, true, is_ret) catch |err| switch (err) { | 24141 | const vector = sema.coerceExtra(block, vector_ty, uncasted_operand, operand_src, .{ .is_ret = is_ret }) catch |err| switch (err) { |
| 24092 | error.NotCoercible => unreachable, | 24142 | error.NotCoercible => unreachable, |
| 24093 | else => |e| return e, | 24143 | else => |e| return e, |
| 24094 | }; | 24144 | }; |
| ... | @@ -24096,7 +24146,7 @@ fn storePtr2( | ... | @@ -24096,7 +24146,7 @@ fn storePtr2( |
| 24096 | return; | 24146 | return; |
| 24097 | } | 24147 | } |
| 24098 | | 24148 | |
| 24099 | const operand = sema.coerceExtra(block, elem_ty, uncasted_operand, operand_src, true, is_ret) catch |err| switch (err) { | 24149 | const operand = sema.coerceExtra(block, elem_ty, uncasted_operand, operand_src, .{ .is_ret = is_ret }) catch |err| switch (err) { |
| 24100 | error.NotCoercible => unreachable, | 24150 | error.NotCoercible => unreachable, |
| 24101 | else => |e| return e, | 24151 | else => |e| return e, |
| 24102 | }; | 24152 | }; |
| ... | @@ -26831,7 +26881,7 @@ fn wrapErrorUnionPayload( | ... | @@ -26831,7 +26881,7 @@ fn wrapErrorUnionPayload( |
| 26831 | inst_src: LazySrcLoc, | 26881 | inst_src: LazySrcLoc, |
| 26832 | ) !Air.Inst.Ref { | 26882 | ) !Air.Inst.Ref { |
| 26833 | const dest_payload_ty = dest_ty.errorUnionPayload(); | 26883 | const dest_payload_ty = dest_ty.errorUnionPayload(); |
| 26834 | const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, false, false); | 26884 | const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false }); |
| 26835 | if (try sema.resolveMaybeUndefVal(block, inst_src, coerced)) |val| { | 26885 | if (try sema.resolveMaybeUndefVal(block, inst_src, coerced)) |val| { |
| 26836 | return sema.addConstant(dest_ty, try Value.Tag.eu_payload.create(sema.arena, val)); | 26886 | return sema.addConstant(dest_ty, try Value.Tag.eu_payload.create(sema.arena, val)); |
| 26837 | } | 26887 | } |