From b4e42042cf27177479f448248601b9be92ca6345 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 6 Oct 2017 12:41:14 -0400 Subject: fix compiler crash when invalid value used closes #527 --- test/compile_errors.zig | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test/compile_errors.zig') diff --git a/test/compile_errors.zig b/test/compile_errors.zig index cbde0e9b99..0ed02b70ca 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2186,4 +2186,49 @@ pub fn addCases(cases: &tests.CompileErrorContext) { , ".tmp_source.zig:3:5: error: alignstack set twice", ".tmp_source.zig:2:5: note: first set here"); + + cases.add("storing runtime value in compile time variable then using it", + \\const Mode = @import("builtin").Mode; + \\ + \\fn Free(comptime filename: []const u8) -> TestCase { + \\ TestCase { + \\ .filename = filename, + \\ .problem_type = ProblemType.Free, + \\ } + \\} + \\ + \\fn LibC(comptime filename: []const u8) -> TestCase { + \\ TestCase { + \\ .filename = filename, + \\ .problem_type = ProblemType.LinkLibC, + \\ } + \\} + \\ + \\const TestCase = struct { + \\ filename: []const u8, + \\ problem_type: ProblemType, + \\}; + \\ + \\const ProblemType = enum { + \\ Free, + \\ LinkLibC, + \\}; + \\ + \\export fn entry() { + \\ const tests = []TestCase { + \\ Free("001"), + \\ Free("002"), + \\ LibC("078"), + \\ Free("116"), + \\ Free("117"), + \\ }; + \\ + \\ for ([]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| { + \\ inline for (tests) |test_case| { + \\ const foo = test_case.filename ++ ".zig"; + \\ } + \\ } + \\} + , + ".tmp_source.zig:37:16: error: cannot store runtime value in compile time variable"); } -- cgit v1.2.3