add compile error for non-inline for loop on comptime type

This commit is contained in:
Andrew Kelley
2018-07-25 17:08:55 -04:00
parent 2257660916
commit 84195467ad
2 changed files with 15 additions and 1 deletions

View File

@@ -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 {}