Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix @compilelog having unintended side effects
closes #1459
  • Loading branch information
andrewrk committed Sep 22, 2018
1 parent 3c1f9ba commit c84548e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/ir.cpp
Expand Up @@ -9874,6 +9874,7 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
if (!const_val)
return ira->codegen->builtin_types.entry_invalid;

assert(const_val->data.x_type != nullptr);
return const_val->data.x_type;
}

Expand Down Expand Up @@ -16880,7 +16881,9 @@ static ZigType *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstruction
}
fprintf(stderr, "\n");

ir_add_error(ira, &instruction->base, buf_sprintf("found compile log statement"));
// Here we bypass higher level functions such as ir_add_error because we do not want
// invalidate_exec to be called.
add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement"));

ir_build_const_from(ira, &instruction->base);
return ira->codegen->builtin_types.entry_void;
Expand Down
17 changes: 14 additions & 3 deletions test/compile_errors.zig
@@ -1,6 +1,20 @@
const tests = @import("tests.zig");

pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"compile log statement inside function which must be comptime evaluated",
\\fn Foo(comptime T: type) type {
\\ @compileLog(@typeName(T));
\\ return T;
\\}
\\export fn entry() void {
\\ _ = Foo(i32);
\\ _ = @typeName(Foo(i32));
\\}
,
".tmp_source.zig:2:5: error: found compile log statement",
);

cases.add(
"comptime slice of an undefined slice",
\\comptime {
Expand Down Expand Up @@ -3472,11 +3486,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\}
,
".tmp_source.zig:5:5: error: found compile log statement",
".tmp_source.zig:2:17: note: called from here",
".tmp_source.zig:6:5: error: found compile log statement",
".tmp_source.zig:2:17: note: called from here",
".tmp_source.zig:7:5: error: found compile log statement",
".tmp_source.zig:2:17: note: called from here",
);

cases.add(
Expand Down

0 comments on commit c84548e

Please sign in to comment.