Skip to content

Commit b18af37

Browse files
committed
fix crash when var init has compile error
and then the var is referenced closes #1483
1 parent 7505529 commit b18af37

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/ir.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
const tests = @import("tests.zig");
22

33
pub 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 {

0 commit comments

Comments
 (0)