authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-22 10:46:22-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-22 10:46:22-04:00
logc84548e71d4990352c202da92d47f1398385411f
treea4c4ee25ba2708c1c3ffb92a9942cff58bfa1677
parent3c1f9baff10be20910fc6e168c293759d9b8537e
signaturelock-open Commit is signed but in an unrecognized format.

fix @compileLog having unintended side effects

closes #1459

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

src/ir.cpp+4-1
...@@ -9874,6 +9874,7 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {...@@ -9874,6 +9874,7 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
9874 if (!const_val)9874 if (!const_val)
9875 return ira->codegen->builtin_types.entry_invalid;9875 return ira->codegen->builtin_types.entry_invalid;
98769876
9877 assert(const_val->data.x_type != nullptr);
9877 return const_val->data.x_type;9878 return const_val->data.x_type;
9878}9879}
98799880
...@@ -16880,7 +16881,9 @@ static ZigType *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstruction...@@ -16880,7 +16881,9 @@ static ZigType *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstruction
16880 }16881 }
16881 fprintf(stderr, "\n");16882 fprintf(stderr, "\n");
1688216883
16883 ir_add_error(ira, &instruction->base, buf_sprintf("found compile log statement"));16884 // Here we bypass higher level functions such as ir_add_error because we do not want
16885 // invalidate_exec to be called.
16886 add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement"));
1688416887
16885 ir_build_const_from(ira, &instruction->base);16888 ir_build_const_from(ira, &instruction->base);
16886 return ira->codegen->builtin_types.entry_void;16889 return ira->codegen->builtin_types.entry_void;
test/compile_errors.zig+14-3
...@@ -1,6 +1,20 @@...@@ -1,6 +1,20 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "compile log statement inside function which must be comptime evaluated",
6 \\fn Foo(comptime T: type) type {
7 \\ @compileLog(@typeName(T));
8 \\ return T;
9 \\}
10 \\export fn entry() void {
11 \\ _ = Foo(i32);
12 \\ _ = @typeName(Foo(i32));
13 \\}
14 ,
15 ".tmp_source.zig:2:5: error: found compile log statement",
16 );
17
4 cases.add(18 cases.add(
5 "comptime slice of an undefined slice",19 "comptime slice of an undefined slice",
6 \\comptime {20 \\comptime {
...@@ -3472,11 +3486,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3472,11 +3486,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3472 \\}3486 \\}
3473 ,3487 ,
3474 ".tmp_source.zig:5:5: error: found compile log statement",3488 ".tmp_source.zig:5:5: error: found compile log statement",
3475 ".tmp_source.zig:2:17: note: called from here",
3476 ".tmp_source.zig:6:5: error: found compile log statement",3489 ".tmp_source.zig:6:5: error: found compile log statement",
3477 ".tmp_source.zig:2:17: note: called from here",
3478 ".tmp_source.zig:7:5: error: found compile log statement",3490 ".tmp_source.zig:7:5: error: found compile log statement",
3479 ".tmp_source.zig:2:17: note: called from here",
3480 );3491 );
34813492
3482 cases.add(3493 cases.add(