| author | |
| committer | |
| log | 84195467ad974f9b7201e4e1bbd6dccbd5e7ab90 |
| tree | 4f7f0a4c239b5fbbd85bb6be5588db8179898802 |
| parent | 2257660916a8c92d953a5a71da6c2d4f7cc031e6 |
2 files changed, 15 insertions(+), 1 deletions(-)
src/ir.cpp+1-1| ... | @@ -12142,7 +12142,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc | ... | @@ -12142,7 +12142,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 12142 | result_type = ira->codegen->builtin_types.entry_invalid; | 12142 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 12143 | } else if (type_requires_comptime(result_type)) { | 12143 | } else if (type_requires_comptime(result_type)) { |
| 12144 | var_class_requires_const = true; | 12144 | var_class_requires_const = true; |
| 12145 | if (!var->src_is_const && !is_comptime_var) { | 12145 | if (!var->gen_is_const && !is_comptime_var) { |
| 12146 | ir_add_error_node(ira, source_node, | 12146 | ir_add_error_node(ira, source_node, |
| 12147 | buf_sprintf("variable of type '%s' must be const or comptime", | 12147 | buf_sprintf("variable of type '%s' must be const or comptime", |
| 12148 | buf_ptr(&result_type->name))); | 12148 | buf_ptr(&result_type->name))); |
test/compile_errors.zig+14| ... | @@ -1,6 +1,20 @@ | ... | @@ -1,6 +1,20 @@ |
| 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 | "non-inline for loop on a type that requires comptime", | ||
| 6 | \\const Foo = struct { | ||
| 7 | \\ name: []const u8, | ||
| 8 | \\ T: type, | ||
| 9 | \\}; | ||
| 10 | \\export fn entry() void { | ||
| 11 | \\ const xx: [2]Foo = undefined; | ||
| 12 | \\ for (xx) |f| {} | ||
| 13 | \\} | ||
| 14 | , | ||
| 15 | ".tmp_source.zig:7:15: error: variable of type 'Foo' must be const or comptime", | ||
| 16 | ); | ||
| 17 | |||
| 4 | cases.add( | 18 | cases.add( |
| 5 | "generic fn as parameter without comptime keyword", | 19 | "generic fn as parameter without comptime keyword", |
| 6 | \\fn f(_: fn (var) void) void {} | 20 | \\fn f(_: fn (var) void) void {} |