authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-07 15:17:24-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-07 15:17:24-04:00
logb18af37c578b118a245c911508d73ed23c303ee0
tree5d05f47eff497583cdf97c0943787d576b6ca60e
parent7505529e448dc9e07e9220addc994dc5b4a524fd
signaturelock-open Commit is signed but in an unrecognized format.

fix crash when var init has compile error

and then the var is referenced closes #1483

2 files changed, 19 insertions(+), 2 deletions(-)

src/ir.cpp+1-2
......@@ -13107,8 +13107,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1310713107 assert(ira->codegen->errors.length != 0);
1310813108 return ira->codegen->invalid_instruction;
1310913109 }
13110 assert(var->value->type);
13111 if (type_is_invalid(var->value->type))
13110 if (var->value->type == nullptr || type_is_invalid(var->value->type))
1311213111 return ira->codegen->invalid_instruction;
1311313112
1311413113 bool comptime_var_mem = ir_get_var_is_comptime(var);
test/compile_errors.zig+18
......@@ -1,6 +1,24 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "variable initialization compile error then referenced",
6 \\fn Undeclared() type {
7 \\ return T;
8 \\}
9 \\fn Gen() type {
10 \\ const X = Undeclared();
11 \\ return struct {
12 \\ x: X,
13 \\ };
14 \\}
15 \\export fn entry() void {
16 \\ const S = Gen();
17 \\}
18 ,
19 ".tmp_source.zig:2:12: error: use of undeclared identifier 'T'",
20 );
21
422 cases.add(
523 "refer to the type of a generic function",
624 \\export fn entry() void {