authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-18 10:22:15+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-18 10:22:15+03:00
log78962eeeda07d613ebdfd239082268a6702c19db
treeecd9d8f2503b69cd49cce34edf5e827c68ba5767
parent39915ae08668884f51071feb4b1132b1903f0abb
signaturelock-open Commit is signed but in an unrecognized format.

fix floatCast type check regression

Closes #5900

2 files changed, 18 insertions(+), 0 deletions(-)

src/ir.cpp+6
......@@ -26739,6 +26739,12 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo
2673926739 }
2674026740 }
2674126741
26742 if (target->value->type->id != ZigTypeIdFloat) {
26743 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'",
26744 buf_ptr(&target->value->type->name)));
26745 return ira->codegen->invalid_inst_gen;
26746 }
26747
2674226748 if (instr_is_comptime(target) || dest_type->id == ZigTypeIdComptimeFloat) {
2674326749 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
2674426750 if (val == nullptr)
test/compile_errors.zig+12
......@@ -122,6 +122,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
122122 \\ var a: u32 = 2;
123123 \\ _ = @floatToInt(u32, a);
124124 \\}
125 \\export fn qux() void {
126 \\ var a: f32 = 2;
127 \\ _ = @intCast(u32, a);
128 \\}
125129 , &[_][]const u8{
126130 "tmp.zig:3:32: error: unable to evaluate constant expression",
127131 "tmp.zig:3:9: note: referenced here",
......@@ -129,6 +133,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
129133 "tmp.zig:7:9: note: referenced here",
130134 "tmp.zig:11:26: error: expected float type, found 'u32'",
131135 "tmp.zig:11:9: note: referenced here",
136 "tmp.zig:15:23: error: expected integer type, found 'f32'",
137 "tmp.zig:15:9: note: referenced here",
132138 });
133139
134140 cases.addTest("invalid float casts",
......@@ -144,6 +150,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
144150 \\ var a: f32 = 2;
145151 \\ _ = @intToFloat(f32, a);
146152 \\}
153 \\export fn qux() void {
154 \\ var a: u32 = 2;
155 \\ _ = @floatCast(f32, a);
156 \\}
147157 , &[_][]const u8{
148158 "tmp.zig:3:36: error: unable to evaluate constant expression",
149159 "tmp.zig:3:9: note: referenced here",
......@@ -151,6 +161,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
151161 "tmp.zig:7:9: note: referenced here",
152162 "tmp.zig:11:26: error: expected int type, found 'f32'",
153163 "tmp.zig:11:9: note: referenced here",
164 "tmp.zig:15:25: error: expected float type, found 'u32'",
165 "tmp.zig:15:9: note: referenced here",
154166 });
155167
156168 cases.addTest("invalid assignments",