| ... | ... | @@ -24307,7 +24307,10 @@ fn coerceExtra( |
| 24307 | 24307 | }, |
| 24308 | 24308 | .Int, .ComptimeInt => switch (inst_ty.zigTypeTag()) { |
| 24309 | 24309 | .Float, .ComptimeFloat => float: { |
| 24310 | | const val = (try sema.resolveDefinedValue(block, inst_src, inst)) orelse { |
| 24310 | if (is_undef) { |
| 24311 | return sema.addConstUndef(dest_ty); |
| 24312 | } |
| 24313 | const val = (try sema.resolveMaybeUndefVal(inst)) orelse { |
| 24311 | 24314 | if (dest_ty.zigTypeTag() == .ComptimeInt) { |
| 24312 | 24315 | if (!opts.report_err) return error.NotCoercible; |
| 24313 | 24316 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime-known"); |
| ... | ... | @@ -24327,7 +24330,10 @@ fn coerceExtra( |
| 24327 | 24330 | return try sema.addConstant(dest_ty, result_val); |
| 24328 | 24331 | }, |
| 24329 | 24332 | .Int, .ComptimeInt => { |
| 24330 | | if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| { |
| 24333 | if (is_undef) { |
| 24334 | return sema.addConstUndef(dest_ty); |
| 24335 | } |
| 24336 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 24331 | 24337 | // comptime-known integer to other number |
| 24332 | 24338 | if (!(try sema.intFitsInType(val, dest_ty, null))) { |
| 24333 | 24339 | if (!opts.report_err) return error.NotCoercible; |
| ... | ... | @@ -24364,7 +24370,10 @@ fn coerceExtra( |
| 24364 | 24370 | return try sema.addConstant(dest_ty, result_val); |
| 24365 | 24371 | }, |
| 24366 | 24372 | .Float => { |
| 24367 | | if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| { |
| 24373 | if (is_undef) { |
| 24374 | return sema.addConstUndef(dest_ty); |
| 24375 | } |
| 24376 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 24368 | 24377 | const result_val = try val.floatCast(sema.arena, dest_ty, target); |
| 24369 | 24378 | if (!val.eql(result_val, dest_ty, sema.mod)) { |
| 24370 | 24379 | return sema.fail( |
| ... | ... | @@ -24389,7 +24398,10 @@ fn coerceExtra( |
| 24389 | 24398 | } |
| 24390 | 24399 | }, |
| 24391 | 24400 | .Int, .ComptimeInt => int: { |
| 24392 | | const val = (try sema.resolveDefinedValue(block, inst_src, inst)) orelse { |
| 24401 | if (is_undef) { |
| 24402 | return sema.addConstUndef(dest_ty); |
| 24403 | } |
| 24404 | const val = (try sema.resolveMaybeUndefVal(inst)) orelse { |
| 24393 | 24405 | if (dest_ty.zigTypeTag() == .ComptimeFloat) { |
| 24394 | 24406 | if (!opts.report_err) return error.NotCoercible; |
| 24395 | 24407 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known"); |