diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-06-16 03:50:56 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-16 03:50:56 -0400 |
| commit | f595545c10a35b85879edfa3c002ce308ffeb6c2 (patch) | |
| tree | 16c24db60fcf42a02902a8e86b07678909b62272 /test | |
| parent | 2bb3e1aff4976b2d04fb08a46d9221c77da0b204 (diff) | |
| parent | a99e61ebaa71aa74dfa95869ea8d02131ef9f696 (diff) | |
| download | zig-f595545c10a35b85879edfa3c002ce308ffeb6c2.tar.gz zig-f595545c10a35b85879edfa3c002ce308ffeb6c2.zip | |
Merge pull request #5422 from pixelherodev/error_tests
[Stage2/Testing] ZIR tests for expected errors
Diffstat (limited to 'test')
| -rw-r--r-- | test/stage2/compile_errors.zig | 45 | ||||
| -rw-r--r-- | test/stage2/zir.zig | 4 |
2 files changed, 47 insertions, 2 deletions
diff --git a/test/stage2/compile_errors.zig b/test/stage2/compile_errors.zig index 9b8dcd91c4..43c41aa364 100644 --- a/test/stage2/compile_errors.zig +++ b/test/stage2/compile_errors.zig @@ -1,8 +1,53 @@ const TestContext = @import("../../src-self-hosted/test.zig").TestContext; +const std = @import("std"); + +const ErrorMsg = @import("../../src-self-hosted/Module.zig").ErrorMsg; + +const linux_x64 = std.zig.CrossTarget{ + .cpu_arch = .x86_64, + .os_tag = .linux, +}; pub fn addCases(ctx: *TestContext) !void { + ctx.addZIRError("call undefined local", linux_x64, + \\@noreturn = primitive(noreturn) + \\ + \\@start_fnty = fntype([], @noreturn, cc=Naked) + \\@start = fn(@start_fnty, { + \\ %0 = call(%test, []) + \\}) + // TODO: address inconsistency in this message and the one in the next test + , &[_][]const u8{":5:13: error: unrecognized identifier: %test"}); + + ctx.addZIRError("call with non-existent target", linux_x64, + \\@noreturn = primitive(noreturn) + \\ + \\@start_fnty = fntype([], @noreturn, cc=Naked) + \\@start = fn(@start_fnty, { + \\ %0 = call(@notafunc, []) + \\}) + \\@0 = str("_start") + \\@1 = ref(@0) + \\@2 = export(@1, @start) + , &[_][]const u8{":5:13: error: use of undeclared identifier 'notafunc'"}); + + // TODO: this error should occur at the call site, not the fntype decl + ctx.addZIRError("call naked function", linux_x64, + \\@noreturn = primitive(noreturn) + \\ + \\@start_fnty = fntype([], @noreturn, cc=Naked) + \\@s = fn(@start_fnty, {}) + \\@start = fn(@start_fnty, { + \\ %0 = call(@s, []) + \\}) + \\@0 = str("_start") + \\@1 = ref(@0) + \\@2 = export(@1, @start) + , &[_][]const u8{":4:9: error: unable to call function with naked calling convention"}); + // TODO: re-enable these tests. // https://github.com/ziglang/zig/issues/1364 + // TODO: add Zig AST -> ZIR testing pipeline //try ctx.testCompileError( // \\export fn entry() void {} diff --git a/test/stage2/zir.zig b/test/stage2/zir.zig index bf5d4b8eae..d58b30c29d 100644 --- a/test/stage2/zir.zig +++ b/test/stage2/zir.zig @@ -92,7 +92,7 @@ pub fn addCases(ctx: *TestContext) void { { var case = ctx.addZIRMulti("reference cycle with compile error in the cycle", linux_x64); - case.addZIR( + case.addTransform( \\@void = primitive(void) \\@fnty = fntype([], @void, cc=C) \\ @@ -171,7 +171,7 @@ pub fn addCases(ctx: *TestContext) void { // Now we remove the call to `a`. `a` and `b` form a cycle, but no entry points are // referencing either of them. This tests that the cycle is detected, and the error // goes away. - case.addZIR( + case.addTransform( \\@void = primitive(void) \\@fnty = fntype([], @void, cc=C) \\ |
