Commit b18af37c57

Andrew Kelley <superjoe30@gmail.com>
2018-09-07 21:17:24
fix crash when var init has compile error
and then the var is referenced closes #1483
1 parent 7505529
Changed files (2)
src/ir.cpp
@@ -13107,8 +13107,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
         assert(ira->codegen->errors.length != 0);
         return ira->codegen->invalid_instruction;
     }
-    assert(var->value->type);
-    if (type_is_invalid(var->value->type))
+    if (var->value->type == nullptr || type_is_invalid(var->value->type))
         return ira->codegen->invalid_instruction;
 
     bool comptime_var_mem = ir_get_var_is_comptime(var);
test/compile_errors.zig
@@ -1,6 +1,24 @@
 const tests = @import("tests.zig");
 
 pub fn addCases(cases: *tests.CompileErrorContext) void {
+    cases.add(
+        "variable initialization compile error then referenced",
+        \\fn Undeclared() type {
+        \\    return T;
+        \\}
+        \\fn Gen() type {
+        \\    const X = Undeclared();
+        \\    return struct {
+        \\        x: X,
+        \\    };
+        \\}
+        \\export fn entry() void {
+        \\    const S = Gen();
+        \\}
+    ,
+        ".tmp_source.zig:2:12: error: use of undeclared identifier 'T'",
+    );
+
     cases.add(
         "refer to the type of a generic function",
         \\export fn entry() void {