| author | |
| committer | |
| log | b18af37c578b118a245c911508d73ed23c303ee0 |
| tree | 5d05f47eff497583cdf97c0943787d576b6ca60e |
| parent | 7505529e448dc9e07e9220addc994dc5b4a524fd |
| signature |
and then the var is referenced
closes #14832 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, | ... | @@ -13107,8 +13107,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 13107 | assert(ira->codegen->errors.length != 0); | 13107 | assert(ira->codegen->errors.length != 0); |
| 13108 | return ira->codegen->invalid_instruction; | 13108 | return ira->codegen->invalid_instruction; |
| 13109 | } | 13109 | } |
| 13110 | assert(var->value->type); | 13110 | if (var->value->type == nullptr || type_is_invalid(var->value->type)) |
| 13111 | if (type_is_invalid(var->value->type)) | ||
| 13112 | return ira->codegen->invalid_instruction; | 13111 | return ira->codegen->invalid_instruction; |
| 13113 | 13112 | ||
| 13114 | bool comptime_var_mem = ir_get_var_is_comptime(var); | 13113 | bool comptime_var_mem = ir_get_var_is_comptime(var); |
test/compile_errors.zig+18| ... | @@ -1,6 +1,24 @@ | ... | @@ -1,6 +1,24 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | ||
| 3 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 3 | 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 | |||
| 4 | cases.add( | 22 | cases.add( |
| 5 | "refer to the type of a generic function", | 23 | "refer to the type of a generic function", |
| 6 | \\export fn entry() void { | 24 | \\export fn entry() void { |