aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-11-16 18:27:17 +0200
committerVeikka Tuominen <git@vexu.eu>2022-11-20 20:25:11 +0200
commit0616d2966a623a005891a2037b49cc2b8ad5b9c4 (patch)
treec082e8fc50b9a9035792ec1948c3d5f1ff997a7c /src
parente5a3eb9777ff165d936b0811f3825eabb8bcd6a4 (diff)
downloadzig-0616d2966a623a005891a2037b49cc2b8ad5b9c4.tar.gz
zig-0616d2966a623a005891a2037b49cc2b8ad5b9c4.zip
Sema: allow coercing typed undefined to int
Closes #13556
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index b3f1dd1bf0..5151904f0b 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -24307,7 +24307,10 @@ fn coerceExtra(
},
.Int, .ComptimeInt => switch (inst_ty.zigTypeTag()) {
.Float, .ComptimeFloat => float: {
- const val = (try sema.resolveDefinedValue(block, inst_src, inst)) orelse {
+ if (is_undef) {
+ return sema.addConstUndef(dest_ty);
+ }
+ const val = (try sema.resolveMaybeUndefVal(inst)) orelse {
if (dest_ty.zigTypeTag() == .ComptimeInt) {
if (!opts.report_err) return error.NotCoercible;
return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime-known");
@@ -24327,7 +24330,10 @@ fn coerceExtra(
return try sema.addConstant(dest_ty, result_val);
},
.Int, .ComptimeInt => {
- if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| {
+ if (is_undef) {
+ return sema.addConstUndef(dest_ty);
+ }
+ if (try sema.resolveMaybeUndefVal(inst)) |val| {
// comptime-known integer to other number
if (!(try sema.intFitsInType(val, dest_ty, null))) {
if (!opts.report_err) return error.NotCoercible;
@@ -24364,7 +24370,10 @@ fn coerceExtra(
return try sema.addConstant(dest_ty, result_val);
},
.Float => {
- if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| {
+ if (is_undef) {
+ return sema.addConstUndef(dest_ty);
+ }
+ if (try sema.resolveMaybeUndefVal(inst)) |val| {
const result_val = try val.floatCast(sema.arena, dest_ty, target);
if (!val.eql(result_val, dest_ty, sema.mod)) {
return sema.fail(
@@ -24389,7 +24398,10 @@ fn coerceExtra(
}
},
.Int, .ComptimeInt => int: {
- const val = (try sema.resolveDefinedValue(block, inst_src, inst)) orelse {
+ if (is_undef) {
+ return sema.addConstUndef(dest_ty);
+ }
+ const val = (try sema.resolveMaybeUndefVal(inst)) orelse {
if (dest_ty.zigTypeTag() == .ComptimeFloat) {
if (!opts.report_err) return error.NotCoercible;
return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known");