| author | |
| committer | |
| log | 1b83ee78a48a64bef28f12b7b2e263074f88b6b6 |
| tree | 14e7cfb300a16966bc562892c5051ea48020ab64 |
| parent | 4bd4c5e06d13c35a70d0207b730fb67b83ff6363 |
| signature |
4 files changed, 16 insertions(+), 9 deletions(-)
src/ir.cpp+3| ... | ... | @@ -9713,6 +9713,9 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 9713 | 9713 | bool const_val_is_float = (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat); |
| 9714 | 9714 | assert(const_val_is_int || const_val_is_float); |
| 9715 | 9715 | |
| 9716 | if (const_val_is_int && other_type->id == ZigTypeIdComptimeFloat) { | |
| 9717 | return true; | |
| 9718 | } | |
| 9716 | 9719 | if (other_type->id == ZigTypeIdFloat) { |
| 9717 | 9720 | if (const_val->type->id == ZigTypeIdComptimeInt || const_val->type->id == ZigTypeIdComptimeFloat) { |
| 9718 | 9721 | return true; |
std/math.zig+7| ... | ... | @@ -305,6 +305,13 @@ test "math.min" { |
| 305 | 305 | testing.expect(@typeOf(result) == i16); |
| 306 | 306 | testing.expect(result == -200); |
| 307 | 307 | } |
| 308 | { | |
| 309 | const a = 10.34; | |
| 310 | var b: f32 = 999.12; | |
| 311 | var result = min(a, b); | |
| 312 | testing.expect(@typeOf(result) == f32); | |
| 313 | testing.expect(result == 10.34); | |
| 314 | } | |
| 308 | 315 | } |
| 309 | 316 | |
| 310 | 317 | pub fn max(x: var, y: var) @typeOf(x + y) { |
test/compile_errors.zig-8| ... | ... | @@ -3225,14 +3225,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3225 | 3225 | "tmp.zig:3:17: note: value 8 cannot fit into type u3", |
| 3226 | 3226 | ); |
| 3227 | 3227 | |
| 3228 | cases.add( | |
| 3229 | "incompatible number literals", | |
| 3230 | \\const x = 2 == 2.0; | |
| 3231 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } | |
| 3232 | , | |
| 3233 | "tmp.zig:1:11: error: integer value 2 cannot be implicitly casted to type 'comptime_float'", | |
| 3234 | ); | |
| 3235 | ||
| 3236 | 3228 | cases.add( |
| 3237 | 3229 | "missing function call param", |
| 3238 | 3230 | \\const Foo = struct { |
test/stage1/behavior/cast.zig+6-1| ... | ... | @@ -508,7 +508,7 @@ test "peer type resolution: unreachable, null, slice" { |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | test "peer type resolution: unreachable, error set, unreachable" { |
| 511 | const Error = error { | |
| 511 | const Error = error{ | |
| 512 | 512 | FileDescriptorAlreadyPresentInSet, |
| 513 | 513 | OperationCausesCircularLoop, |
| 514 | 514 | FileDescriptorNotRegistered, |
| ... | ... | @@ -529,3 +529,8 @@ test "peer type resolution: unreachable, error set, unreachable" { |
| 529 | 529 | }; |
| 530 | 530 | expect(transformed_err == error.SystemResources); |
| 531 | 531 | } |
| 532 | ||
| 533 | test "implicit cast comptime_int to comptime_float" { | |
| 534 | comptime expect(comptime_float(10) == f32(10)); | |
| 535 | expect(2 == 2.0); | |
| 536 | } |