Skip to content

Commit

Permalink
add compile error for non-inline for loop on comptime type
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Jul 25, 2018
1 parent 2257660 commit 8419546
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ir.cpp
Expand Up @@ -12142,7 +12142,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
result_type = ira->codegen->builtin_types.entry_invalid;
} else if (type_requires_comptime(result_type)) {
var_class_requires_const = true;
if (!var->src_is_const && !is_comptime_var) {
if (!var->gen_is_const && !is_comptime_var) {
ir_add_error_node(ira, source_node,
buf_sprintf("variable of type '%s' must be const or comptime",
buf_ptr(&result_type->name)));
Expand Down
14 changes: 14 additions & 0 deletions test/compile_errors.zig
@@ -1,6 +1,20 @@
const tests = @import("tests.zig");

pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"non-inline for loop on a type that requires comptime",
\\const Foo = struct {
\\ name: []const u8,
\\ T: type,
\\};
\\export fn entry() void {
\\ const xx: [2]Foo = undefined;
\\ for (xx) |f| {}
\\}
,
".tmp_source.zig:7:15: error: variable of type 'Foo' must be const or comptime",
);

cases.add(
"generic fn as parameter without comptime keyword",
\\fn f(_: fn (var) void) void {}
Expand Down

0 comments on commit 8419546

Please sign in to comment.