From 258bc73eee557ada944c9d25ed85d9baf8035ad7 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 2 Jan 2016 20:13:10 -0700 Subject: fix implicit cast after unreachable bad code gen --- test/run_tests.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/run_tests.cpp') diff --git a/test/run_tests.cpp b/test/run_tests.cpp index 839109a1ab..645d8295fa 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -682,6 +682,21 @@ export fn main(argc : isize, argv : &&u8, env : &&u8) -> i32 { return 0; } )SOURCE", "x is true\n"); + + add_simple_case("implicit cast after unreachable", R"SOURCE( +use "std.zig"; +export fn main(argc : isize, argv : &&u8, env : &&u8) -> i32 { + const x = outer(); + if (x == 1234) { + print_str("OK\n"); + } + return 0; +} +fn inner() -> i32 { 1234 } +fn outer() -> isize { + return inner(); +} + )SOURCE", "OK\n"); } //////////////////////////////////////////////////////////////////////////////////// @@ -978,6 +993,12 @@ fn f() { if (const x ?= true) { } } )SOURCE", 1, ".tmp_source.zig:3:20: error: expected maybe type"); + + add_compile_fail_case("cast unreachable", R"SOURCE( +fn f() -> i32 { + (return 1) as i32 +} + )SOURCE", 1, ".tmp_source.zig:3:16: error: invalid cast from type 'unreachable' to 'i32'"); } static void print_compiler_invocation(TestCase *test_case) { -- cgit v1.2.3