Commit b18af37c57
Changed files (2)
src
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 {