fix crash on runtime index into slice of comptime type

closes #1435
This commit is contained in:
Andrew Kelley
2018-09-25 12:03:39 -04:00
parent 839492d0e8
commit 2e562a5f36
3 changed files with 27 additions and 2 deletions

View File

@@ -1,6 +1,22 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"runtime index into comptime type slice",
\\const Struct = struct {
\\ a: u32,
\\};
\\fn getIndex() usize {
\\ return 2;
\\}
\\export fn entry() void {
\\ const index = getIndex();
\\ const field = @typeInfo(Struct).Struct.fields[index];
\\}
,
".tmp_source.zig:9:51: error: values of type 'StructField' must be comptime known, but index value is runtime known",
);
cases.add(
"compile log statement inside function which must be comptime evaluated",
\\fn Foo(comptime T: type) type {