diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-07-10 14:03:03 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-07-10 14:03:03 -0400 |
| commit | cfaebb20d8906d31cedc59e39e6a9286967a931a (patch) | |
| tree | 33d0c3994bfb658937e2e692a946bc8a2eca4fe5 /test/compile_errors.zig | |
| parent | b5d07297dec61a3993dfe91ceee2c87672db1e8e (diff) | |
| parent | 0ce6934e2631eb3beca817d3bce12ecb13aafa13 (diff) | |
| download | zig-cfaebb20d8906d31cedc59e39e6a9286967a931a.tar.gz zig-cfaebb20d8906d31cedc59e39e6a9286967a931a.zip | |
Merge remote-tracking branch 'origin/master' into llvm7
Diffstat (limited to 'test/compile_errors.zig')
| -rw-r--r-- | test/compile_errors.zig | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 7291a48a8f..a6db8d50b4 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,90 @@ const tests = @import("tests.zig"); pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( + "use of comptime-known undefined function value", + \\const Cmd = struct { + \\ exec: fn () void, + \\}; + \\export fn entry() void { + \\ const command = Cmd{ .exec = undefined }; + \\ command.exec(); + \\} + , + ".tmp_source.zig:6:12: error: use of undefined value", + ); + + cases.add( + "bad @alignCast at comptime", + \\comptime { + \\ const ptr = @intToPtr(*i32, 0x1); + \\ const aligned = @alignCast(4, ptr); + \\} + , + ".tmp_source.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", + ); + + cases.add( + "@ptrToInt on *void", + \\export fn entry() bool { + \\ return @ptrToInt(&{}) == @ptrToInt(&{}); + \\} + , + ".tmp_source.zig:2:23: error: pointer to size 0 type has no address", + ); + + cases.add( + "@popCount - non-integer", + \\export fn entry(x: f32) u32 { + \\ return @popCount(x); + \\} + , + ".tmp_source.zig:2:22: error: expected integer type, found 'f32'", + ); + + cases.add( + "@popCount - negative comptime_int", + \\comptime { + \\ _ = @popCount(-1); + \\} + , + ".tmp_source.zig:2:9: error: @popCount on negative comptime_int value -1", + ); + + cases.addCase(x: { + const tc = cases.create( + "wrong same named struct", + \\const a = @import("a.zig"); + \\const b = @import("b.zig"); + \\ + \\export fn entry() void { + \\ var a1: a.Foo = undefined; + \\ bar(&a1); + \\} + \\ + \\fn bar(x: *b.Foo) void {} + , + ".tmp_source.zig:6:10: error: expected type '*Foo', found '*Foo'", + ".tmp_source.zig:6:10: note: pointer type child 'Foo' cannot cast into pointer type child 'Foo'", + "a.zig:1:17: note: Foo declared here", + "b.zig:1:17: note: Foo declared here", + ); + + tc.addSourceFile("a.zig", + \\pub const Foo = struct { + \\ x: i32, + \\}; + ); + + tc.addSourceFile("b.zig", + \\pub const Foo = struct { + \\ z: f64, + \\}; + ); + + break :x tc; + }); + + cases.add( "enum field value references enum", \\pub const Foo = extern enum { \\ A = Foo.B, @@ -358,6 +442,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { ".tmp_source.zig:3:14: note: other value is here", ); + cases.add("invalid cast from integral type to enum", + \\const E = enum(usize) { One, Two }; + \\ + \\export fn entry() void { + \\ foo(1); + \\} + \\ + \\fn foo(x: usize) void { + \\ switch (x) { + \\ E.One => {}, + \\ } + \\} + , ".tmp_source.zig:9:10: error: expected type 'usize', found 'E'"); + cases.add( "range operator in switch used on error set", \\export fn entry() void { |
