aboutsummaryrefslogtreecommitdiff
path: root/test/compile_errors.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-09-25 12:03:39 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-09-25 12:03:39 -0400
commit2e562a5f366aabefd34a4191b2cd0b5e72d3d089 (patch)
tree96192ee77cac902e9954d534a5009c4c04e28855 /test/compile_errors.zig
parent839492d0e82e5d7b2a5cee54acb9e64b414e9817 (diff)
downloadzig-2e562a5f366aabefd34a4191b2cd0b5e72d3d089.tar.gz
zig-2e562a5f366aabefd34a4191b2cd0b5e72d3d089.zip
fix crash on runtime index into slice of comptime type
closes #1435
Diffstat (limited to 'test/compile_errors.zig')
-rw-r--r--test/compile_errors.zig16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 5d9fb84c71..d5d0cb38f2 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -2,6 +2,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 {
\\ @compileLog(@typeName(T));