Skip to content

Commit 8419546

Browse files
committedJul 25, 2018
add compile error for non-inline for loop on comptime type
·
0.15.10.3.0
1 parent 2257660 commit 8419546

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎src/ir.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12142,7 +12142,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
1214212142
result_type = ira->codegen->builtin_types.entry_invalid;
1214312143
} else if (type_requires_comptime(result_type)) {
1214412144
var_class_requires_const = true;
12145-
if (!var->src_is_const && !is_comptime_var) {
12145+
if (!var->gen_is_const && !is_comptime_var) {
1214612146
ir_add_error_node(ira, source_node,
1214712147
buf_sprintf("variable of type '%s' must be const or comptime",
1214812148
buf_ptr(&result_type->name)));

‎test/compile_errors.zig‎

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

33
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+
418
cases.add(
519
"generic fn as parameter without comptime keyword",
620
\\fn f(_: fn (var) void) void {}

0 commit comments

Comments
 (0)
Please sign in to comment.