fix crash when var init has compile error

and then the var is referenced

closes #1483
This commit is contained in:
Andrew Kelley 2018-09-07 15:17:24 -04:00
parent 7505529e44
commit b18af37c57
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
2 changed files with 19 additions and 2 deletions

View File

@ -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);

View File

@ -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 {