2017-04-19 11:00:12 -07:00
const tests = @import ( " tests.zig " ) ;
2019-02-25 18:46:32 -08:00
const builtin = @import ( " builtin " ) ;
2017-04-19 01:12:22 -07:00
2018-05-31 07:56:59 -07:00
pub fn addCases ( cases : * tests . CompileErrorContext ) void {
2019-11-25 15:46:17 -08:00
cases . addCase ( x : {
var tc = cases . create ( " @newStackCall on unsupported target " ,
\\export fn entry() void {
\\ var buf: [10]u8 align(16) = undefined;
\\ @newStackCall(&buf, foo);
\\}
\\fn foo() void {}
, " tmp.zig:3:5: error: target arch 'wasm32' does not support @newStackCall " ) ;
tc . target = tests . Target {
. Cross = tests . CrossTarget {
. arch = . wasm32 ,
. os = . wasi ,
. abi = . none ,
} ,
} ;
break : x tc ;
} ) ;
2019-11-24 14:02:56 -08:00
cases . add (
2019-11-24 17:25:14 -08:00
" incompatible sentinels " ,
2019-11-24 14:02:56 -08:00
\\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
\\ return ptr;
\\}
\\export fn entry2(ptr: [*]u8) [*:0]u8 {
\\ return ptr;
\\}
2019-11-24 17:25:14 -08:00
\\export fn entry3() void {
\\ var array: [2:0]u8 = [_:255]u8{1, 2};
\\}
\\export fn entry4() void {
\\ var array: [2:0]u8 = [_]u8{1, 2};
\\}
2019-11-24 14:02:56 -08:00
,
2019-11-24 15:10:31 -08:00
" tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8' " ,
2019-11-24 17:25:14 -08:00
" tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel " ,
2019-11-24 15:10:31 -08:00
" tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8' " ,
2019-11-24 17:25:14 -08:00
" tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel " ,
" tmp.zig:8:35: error: expected type '[2:0]u8', found '[2:255]u8' " ,
" tmp.zig:8:35: note: destination array requires a terminating '0' sentinel, but source array has a terminating '255' sentinel " ,
" tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8' " ,
" tmp.zig:11:31: note: destination array requires a terminating '0' sentinel " ,
2019-11-24 14:02:56 -08:00
) ;
2019-11-20 10:34:20 -08:00
cases . add (
" empty switch on an integer " ,
\\export fn entry() void {
\\ var x: u32 = 0;
\\ switch(x) {}
\\}
,
" tmp.zig:3:5: error: switch must handle all possibilities " ,
) ;
2019-11-19 07:29:43 -08:00
cases . add (
" incorrect return type " ,
\\ pub export fn entry() void{
\\ _ = foo();
\\ }
\\ const A = struct {
\\ a: u32,
\\ };
\\ fn foo() A {
\\ return bar();
\\ }
\\ const B = struct {
\\ a: u32,
\\ };
\\ fn bar() B {
\\ unreachable;
\\ }
,
" tmp.zig:8:16: error: expected type 'A', found 'B' " ,
) ;
2019-11-18 16:59:03 -08:00
cases . add (
" regression test #2980: base type u32 is not type checked properly when assigning a value within a struct " ,
\\const Foo = struct {
\\ ptr: ?*usize,
\\ uval: u32,
\\};
\\fn get_uval(x: u32) !u32 {
\\ return error.NotFound;
\\}
\\export fn entry() void {
\\ const afoo = Foo{
\\ .ptr = null,
\\ .uval = get_uval(42),
\\ };
\\}
,
" tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32' " ,
) ;
2019-11-19 12:54:32 -08:00
cases . add (
" function call assigned to incorrect type " ,
\\export fn entry() void {
\\ var arr: [4]f32 = undefined;
\\ arr = concat();
\\}
\\fn concat() [16]f32 {
\\ return [1]f32{0}**16;
\\}
,
" tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32' "
) ;
2019-11-19 21:54:47 -08:00
cases . add (
" generic function call assigned to incorrect type " ,
\\pub export fn entry() void {
\\ var res: []i32 = undefined;
\\ res = myAlloc(i32);
\\}
\\fn myAlloc(comptime arg: type) anyerror!arg{
\\ unreachable;
\\}
,
" tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32 "
) ;
2019-11-18 14:31:35 -08:00
cases . add (
" asigning to struct or union fields that are not optionals with a function that returns an optional " ,
\\fn maybe(is: bool) ?u8 {
\\ if (is) return @as(u8, 10) else return null;
\\}
\\const U = union {
\\ Ye: u8,
\\};
\\const S = struct {
\\ num: u8,
\\};
\\export fn entry() void {
\\ var u = U{ .Ye = maybe(false) };
\\ var s = S{ .num = maybe(false) };
\\}
,
" tmp.zig:11:27: error: expected type 'u8', found '?u8' " ,
) ;
2019-11-17 07:55:38 -08:00
cases . add (
" missing result type for phi node " ,
\\fn foo() !void {
\\ return anyerror.Foo;
\\}
\\export fn entry() void {
\\ foo() catch 0;
\\}
,
" tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void' " ,
) ;
2019-11-13 02:05:15 -08:00
cases . add (
" atomicrmw with enum op not .Xchg " ,
\\export fn entry() void {
\\ const E = enum(u8) {
\\ a,
\\ b,
\\ c,
\\ d,
\\ };
\\ var x: E = .a;
\\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
\\}
,
" tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg " ,
) ;
2019-11-14 00:26:33 -08:00
cases . add (
" disallow coercion from non-null-terminated pointer to null-terminated pointer " ,
2019-11-23 23:14:21 -08:00
\\extern fn puts(s: [*:0]const u8) c_int;
2019-11-14 00:26:33 -08:00
\\pub fn main() void {
\\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'};
\\ const no_zero_ptr: [*]const u8 = &no_zero_array;
\\ _ = puts(no_zero_ptr);
\\}
,
2019-11-23 23:14:21 -08:00
" tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8' " ,
2019-11-14 00:26:33 -08:00
) ;
2019-11-12 15:32:16 -08:00
cases . add (
" atomic orderings of atomicStore Acquire or AcqRel " ,
\\export fn entry() void {
\\ var x: u32 = 0;
\\ @atomicStore(u32, &x, 1, .Acquire);
\\}
,
" tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel " ,
) ;
2019-11-11 15:01:27 -08:00
cases . add (
" missing const in slice with nested array type " ,
\\const Geo3DTex2D = struct { vertices: [][2]f32 };
\\pub fn getGeo3DTex2D() Geo3DTex2D {
\\ return Geo3DTex2D{
\\ .vertices = [_][2]f32{
\\ [_]f32{ -0.5, -0.5},
\\ },
\\ };
\\}
\\export fn entry() void {
\\ var geo_data = getGeo3DTex2D();
\\}
,
" tmp.zig:4:30: error: expected type '[][2]f32', found '[1][2]f32' " ,
) ;
2019-11-04 06:09:11 -08:00
cases . add (
" slicing of global undefined pointer " ,
\\var buf: *[1]u8 = undefined;
\\export fn entry() void {
\\ _ = buf[0..1];
\\}
,
" tmp.zig:3:12: error: non-zero length slice of undefined pointer " ,
) ;
2019-11-04 01:11:33 -08:00
cases . add (
" using invalid types in function call raises an error " ,
\\const MenuEffect = enum {};
\\fn func(effect: MenuEffect) void {}
\\export fn entry() void {
\\ func(MenuEffect.ThisDoesNotExist);
\\}
,
" tmp.zig:1:20: error: enums must have 1 or more fields " ,
" tmp.zig:4:20: note: referenced here " ,
) ;
2019-11-01 19:57:19 -07:00
cases . add (
2019-11-01 20:16:49 -07:00
" store vector pointer with unknown runtime index " ,
\\export fn entry() void {
\\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
\\
\\ var i: u32 = 0;
\\ storev(&v[i], 42);
\\}
\\
\\fn storev(ptr: var, val: i32) void {
\\ ptr.* = val;
\\}
,
" tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32 " ,
) ;
cases . add (
" load vector pointer with unknown runtime index " ,
2019-11-01 19:57:19 -07:00
\\export fn entry() void {
\\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
\\
\\ var i: u32 = 0;
\\ var x = loadv(&v[i]);
\\}
\\
\\fn loadv(ptr: var) i32 {
\\ return ptr.*;
\\}
,
" tmp.zig:9:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32 " ,
) ;
2019-10-24 13:23:33 -07:00
cases . add (
" using an unknown len ptr type instead of array " ,
\\const resolutions = [*][*]const u8{
2019-11-19 17:29:08 -08:00
\\ "[320 240 ]",
2019-10-24 13:23:33 -07:00
\\ null,
\\};
\\comptime {
\\ _ = resolutions;
\\}
,
" tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8' " ,
) ;
2019-10-20 13:56:58 -07:00
cases . add (
" comparison with error union and error value " ,
\\export fn entry() void {
\\ var number_or_error: anyerror!i32 = error.SomethingAwful;
\\ _ = number_or_error == error.SomethingAwful;
\\}
,
" tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32' " ,
) ;
2019-09-23 02:14:36 -07:00
cases . add (
" switch with overlapping case ranges " ,
\\export fn entry() void {
\\ var q: u8 = 0;
\\ switch (q) {
\\ 1...2 => {},
\\ 0...255 => {},
\\ }
\\}
,
" tmp.zig:5:9: error: duplicate switch value " ,
) ;
2019-09-17 23:54:59 -07:00
cases . add (
" invalid optional type in extern struct " ,
\\const stroo = extern struct {
\\ moo: ?[*c]u8,
\\};
\\export fn testf(fluff: *stroo) void {}
,
" tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8' " ,
) ;
2019-09-05 09:43:54 -07:00
cases . add (
" attempt to negate a non-integer, non-float or non-vector type " ,
\\fn foo() anyerror!u32 {
\\ return 1;
\\}
\\
\\export fn entry() void {
\\ const x = -foo();
\\}
,
" tmp.zig:6:15: error: negation of type 'anyerror!u32' " ,
) ;
2019-09-04 08:08:28 -07:00
cases . add (
" attempt to create 17 bit float type " ,
\\const builtin = @import("builtin");
\\comptime {
\\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } });
\\}
,
" tmp.zig:3:32: error: 17-bit float unsupported " ,
) ;
2019-08-23 08:33:33 -07:00
cases . add (
" wrong type for @Type " ,
\\export fn entry() void {
\\ _ = @Type(0);
\\}
,
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
`@import("std").builtin`. The target-related types are moved
to `std.Target`. This allows the data types to have methods, such as
`std.Target.current.isDarwin()`.
* `std.os.windows.subsystem` is moved to
`std.Target.current.subsystem`.
* Remove the concept of the panic package from the compiler
implementation. Instead, `std.builtin.panic` is always the panic
function. It checks for `@hasDecl(@import("root"), "panic")`,
or else provides a default implementation.
This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 15:43:24 -07:00
" tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int' " ,
2019-08-23 08:33:33 -07:00
) ;
cases . add (
" @Type with non-constant expression " ,
\\const builtin = @import("builtin");
\\var globalTypeInfo : builtin.TypeInfo = undefined;
\\export fn entry() void {
\\ _ = @Type(globalTypeInfo);
\\}
,
" tmp.zig:4:15: error: unable to evaluate constant expression " ,
) ;
cases . add (
" @Type with TypeInfo.Int " ,
\\const builtin = @import("builtin");
\\export fn entry() void {
\\ _ = @Type(builtin.TypeInfo.Int {
\\ .is_signed = true,
\\ .bits = 8,
\\ });
\\}
,
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
`@import("std").builtin`. The target-related types are moved
to `std.Target`. This allows the data types to have methods, such as
`std.Target.current.isDarwin()`.
* `std.os.windows.subsystem` is moved to
`std.Target.current.subsystem`.
* Remove the concept of the panic package from the compiler
implementation. Instead, `std.builtin.panic` is always the panic
function. It checks for `@hasDecl(@import("root"), "panic")`,
or else provides a default implementation.
This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 15:43:24 -07:00
" tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int' " ,
2019-08-23 08:33:33 -07:00
) ;
cases . add (
" Struct unavailable for @Type " ,
\\export fn entry() void {
\\ _ = @Type(@typeInfo(struct { }));
\\}
,
" tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct' " ,
) ;
2019-08-31 15:50:16 -07:00
cases . add (
" wrong type for result ptr to @asyncCall " ,
\\export fn entry() void {
\\ _ = async amain();
\\}
\\fn amain() i32 {
\\ var frame: @Frame(foo) = undefined;
\\ return await @asyncCall(&frame, false, foo);
\\}
\\fn foo() i32 {
\\ return 1234;
\\}
,
" tmp.zig:6:37: error: expected type '*i32', found 'bool' " ,
) ;
2019-08-28 14:12:42 -07:00
cases . add (
" shift amount has to be an integer type " ,
\\export fn entry() void {
2019-11-06 20:25:57 -08:00
\\ const x = 1 << &@as(u8, 10);
2019-08-28 14:12:42 -07:00
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8' " ,
2019-08-28 14:12:42 -07:00
" tmp.zig:2:17: note: referenced here " ,
) ;
cases . add (
" bit shifting only works on integer types " ,
\\export fn entry() void {
2019-11-06 20:25:57 -08:00
\\ const x = &@as(u8, 1) << 10;
2019-08-28 14:12:42 -07:00
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8' " ,
" tmp.zig:2:27: note: referenced here " ,
2019-08-28 14:12:42 -07:00
) ;
2019-08-31 15:50:16 -07:00
2019-08-27 10:59:18 -07:00
cases . add (
" struct depends on itself via optional field " ,
\\const LhsExpr = struct {
\\ rhsExpr: ?AstObject,
\\};
\\const AstObject = union {
\\ lhsExpr: LhsExpr,
\\};
\\export fn entry() void {
\\ const lhsExpr = LhsExpr{ .rhsExpr = null };
\\ const obj = AstObject{ .lhsExpr = lhsExpr };
\\}
,
2019-11-10 18:58:05 -08:00
" tmp.zig:1:17: error: struct 'LhsExpr' depends on itself " ,
2019-10-30 16:27:42 -07:00
" tmp.zig:5:5: note: while checking this field " ,
2019-11-10 18:58:05 -08:00
" tmp.zig:2:5: note: while checking this field " ,
2019-08-27 10:59:18 -07:00
) ;
2019-08-27 09:54:50 -07:00
cases . add (
" alignment of enum field specified " ,
\\const Number = enum {
\\ a,
\\ b align(i32),
\\};
\\export fn entry1() void {
\\ var x: Number = undefined;
\\}
,
" tmp.zig:3:13: error: structs and unions, not enums, support field alignment " ,
" tmp.zig:1:16: note: consider 'union(enum)' here " ,
) ;
cases . add (
" bad alignment type " ,
\\export fn entry1() void {
\\ var x: []align(true) i32 = undefined;
\\}
\\export fn entry2() void {
2019-11-06 20:25:57 -08:00
\\ var x: *align(@as(f64, 12.34)) i32 = undefined;
2019-08-27 09:54:50 -07:00
\\}
,
" tmp.zig:2:20: error: expected type 'u29', found 'bool' " ,
2019-11-08 12:56:21 -08:00
" tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29' " ,
2019-08-27 09:54:50 -07:00
) ;
2019-08-20 11:40:57 -07:00
cases . addCase ( x : {
var tc = cases . create ( " variable in inline assembly template cannot be found " ,
\\export fn entry() void {
\\ var sp = asm volatile (
\\ "mov %[foo], sp"
\\ : [bar] "=r" (-> usize)
\\ );
\\}
2019-08-26 09:43:36 -07:00
, " tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs " ) ;
2019-08-20 11:40:57 -07:00
tc . target = tests . Target {
. Cross = tests . CrossTarget {
. arch = . x86_64 ,
. os = . linux ,
. abi = . gnu ,
} ,
} ;
break : x tc ;
} ) ;
2019-08-17 05:16:51 -07:00
2019-08-17 16:47:49 -07:00
cases . add (
" indirect recursion of async functions detected " ,
\\var frame: ?anyframe = null;
\\
\\export fn a() void {
\\ _ = async rangeSum(10);
\\ while (frame) |f| resume f;
\\}
\\
\\fn rangeSum(x: i32) i32 {
\\ suspend {
\\ frame = @frame();
\\ }
\\ frame = null;
\\
\\ if (x == 0) return 0;
\\ var child = rangeSumIndirect(x - 1);
\\ return child + 1;
\\}
\\
\\fn rangeSumIndirect(x: i32) i32 {
\\ suspend {
\\ frame = @frame();
\\ }
\\ frame = null;
\\
\\ if (x == 0) return 0;
\\ var child = rangeSum(x - 1);
\\ return child + 1;
\\}
,
" tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself " ,
2019-08-26 09:43:36 -07:00
" tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here " ,
" tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here " ,
2019-08-17 16:47:49 -07:00
) ;
2019-08-17 13:49:23 -07:00
cases . add (
" non-async function pointer eventually is inferred to become async " ,
\\export fn a() void {
\\ var non_async_fn: fn () void = undefined;
\\ non_async_fn = func;
\\}
\\fn func() void {
\\ suspend;
\\}
,
" tmp.zig:5:1: error: 'func' cannot be async " ,
" tmp.zig:3:20: note: required to be non-async here " ,
" tmp.zig:6:5: note: suspends here " ,
) ;
2019-08-17 09:48:48 -07:00
cases . add (
" bad alignment in @asyncCall " ,
\\export fn entry() void {
\\ var ptr: async fn () void = func;
\\ var bytes: [64]u8 = undefined;
\\ _ = @asyncCall(&bytes, {}, ptr);
\\}
\\async fn func() void {}
,
" tmp.zig:4:21: error: expected type '[]align(16) u8', found '*[64]u8' " ,
) ;
2019-08-17 12:51:25 -07:00
cases . add (
" atomic orderings of fence Acquire or stricter " ,
\\export fn entry() void {
\\ @fence(.Monotonic);
\\}
,
" tmp.zig:2:12: error: atomic ordering must be Acquire or stricter " ,
) ;
2019-08-17 09:48:48 -07:00
cases . add (
" bad alignment in implicit cast from array pointer to slice " ,
\\export fn a() void {
\\ var x: [10]u8 = undefined;
\\ var y: []align(16) u8 = &x;
\\}
,
" tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8' " ,
) ;
2019-08-16 13:30:24 -07:00
cases . add (
" result location incompatibility mismatching handle_is_ptr (generic call) " ,
\\export fn entry() void {
\\ var damn = Container{
\\ .not_optional = getOptional(i32),
\\ };
\\}
\\pub fn getOptional(comptime T: type) ?T {
\\ return 0;
\\}
\\pub const Container = struct {
\\ not_optional: i32,
\\};
,
" tmp.zig:3:36: error: expected type 'i32', found '?i32' " ,
) ;
cases . add (
" result location incompatibility mismatching handle_is_ptr " ,
\\export fn entry() void {
\\ var damn = Container{
\\ .not_optional = getOptional(),
\\ };
\\}
\\pub fn getOptional() ?i32 {
\\ return 0;
\\}
\\pub const Container = struct {
\\ not_optional: i32,
\\};
,
" tmp.zig:3:36: error: expected type 'i32', found '?i32' " ,
) ;
2019-08-16 08:27:29 -07:00
cases . add (
" const frame cast to anyframe " ,
\\export fn a() void {
\\ const f = async func();
\\ resume f;
\\}
\\export fn b() void {
\\ const f = async func();
\\ var x: anyframe = &f;
\\}
\\fn func() void {
\\ suspend;
\\}
,
" tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)' " ,
" tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)' " ,
) ;
2019-08-16 08:00:21 -07:00
cases . add (
" prevent bad implicit casting of anyframe types " ,
\\export fn a() void {
\\ var x: anyframe = undefined;
\\ var y: anyframe->i32 = x;
\\}
\\export fn b() void {
\\ var x: i32 = undefined;
\\ var y: anyframe->i32 = x;
\\}
\\export fn c() void {
\\ var x: @Frame(func) = undefined;
\\ var y: anyframe->i32 = &x;
\\}
\\fn func() void {}
,
" tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe' " ,
" tmp.zig:7:28: error: expected type 'anyframe->i32', found 'i32' " ,
" tmp.zig:11:29: error: expected type 'anyframe->i32', found '*@Frame(func)' " ,
) ;
2019-08-16 07:49:00 -07:00
cases . add (
" wrong frame type used for async call " ,
\\export fn entry() void {
\\ var frame: @Frame(foo) = undefined;
\\ frame = async bar();
\\}
\\fn foo() void {
\\ suspend;
\\}
\\fn bar() void {
\\ suspend;
\\}
,
" tmp.zig:3:5: error: expected type '*@Frame(bar)', found '*@Frame(foo)' " ,
) ;
2019-08-16 07:44:42 -07:00
cases . add (
" @Frame() of generic function " ,
\\export fn entry() void {
\\ var frame: @Frame(func) = undefined;
\\}
\\fn func(comptime T: type) void {
\\ var x: T = undefined;
\\}
,
" tmp.zig:2:16: error: @Frame() of generic function " ,
) ;
2019-08-15 12:06:05 -07:00
cases . add (
" @frame() causes function to be async " ,
\\export fn entry() void {
\\ func();
\\}
\\fn func() void {
\\ _ = @frame();
\\}
,
" tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async " ,
" tmp.zig:5:9: note: @frame() causes function to be async " ,
) ;
2019-08-16 07:44:42 -07:00
2019-08-14 08:22:12 -07:00
cases . add (
" invalid suspend in exported function " ,
\\export fn entry() void {
\\ var frame = async func();
\\ var result = await frame;
\\}
\\fn func() void {
\\ suspend;
\\}
,
" tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async " ,
2019-08-29 19:44:07 -07:00
" tmp.zig:3:18: note: await here is a suspend point " ,
2019-08-14 08:22:12 -07:00
) ;
2019-08-08 10:44:57 -07:00
cases . add (
" async function indirectly depends on its own frame " ,
\\export fn entry() void {
\\ _ = async amain();
\\}
\\async fn amain() void {
\\ other();
\\}
\\fn other() void {
\\ var x: [@sizeOf(@Frame(amain))]u8 = undefined;
\\}
,
" tmp.zig:4:1: error: unable to determine async function frame of 'amain' " ,
" tmp.zig:5:10: note: analysis of function 'other' depends on the frame " ,
2019-08-26 09:43:36 -07:00
" tmp.zig:8:13: note: referenced here " ,
2019-08-08 10:44:57 -07:00
) ;
cases . add (
" async function depends on its own frame " ,
\\export fn entry() void {
\\ _ = async amain();
\\}
\\async fn amain() void {
\\ var x: [@sizeOf(@Frame(amain))]u8 = undefined;
\\}
,
" tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet " ,
2019-08-26 09:43:36 -07:00
" tmp.zig:5:13: note: referenced here " ,
2019-08-08 10:44:57 -07:00
) ;
2019-08-03 13:14:24 -07:00
cases . add (
" non async function pointer passed to @asyncCall " ,
\\export fn entry() void {
\\ var ptr = afunc;
2019-08-17 09:48:48 -07:00
\\ var bytes: [100]u8 align(16) = undefined;
2019-08-03 13:14:24 -07:00
\\ _ = @asyncCall(&bytes, {}, ptr);
\\}
\\fn afunc() void { }
,
" tmp.zig:4:32: error: expected async function, found 'fn() void' " ,
) ;
2019-08-02 23:40:38 -07:00
cases . add (
" runtime-known async function called " ,
\\export fn entry() void {
2019-08-15 11:05:12 -07:00
\\ _ = async amain();
\\}
\\fn amain() void {
2019-08-02 23:40:38 -07:00
\\ var ptr = afunc;
\\ _ = ptr();
\\}
\\async fn afunc() void {}
,
2019-08-15 11:05:12 -07:00
" tmp.zig:6:12: error: function is not comptime-known; @asyncCall required " ,
2019-08-02 23:40:38 -07:00
) ;
2019-08-02 22:06:14 -07:00
cases . add (
" runtime-known function called with async keyword " ,
\\export fn entry() void {
\\ var ptr = afunc;
\\ _ = async ptr();
\\}
\\
\\async fn afunc() void { }
,
" tmp.zig:3:15: error: function is not comptime-known; @asyncCall required " ,
) ;
2019-07-23 16:35:41 -07:00
cases . add (
" function with ccc indirectly calling async function " ,
\\export fn entry() void {
\\ foo();
\\}
\\fn foo() void {
\\ bar();
\\}
\\fn bar() void {
\\ suspend;
\\}
,
" tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async " ,
" tmp.zig:2:8: note: async function call here " ,
" tmp.zig:5:8: note: async function call here " ,
" tmp.zig:8:5: note: suspends here " ,
) ;
2019-07-03 21:35:28 -07:00
cases . add (
" capture group on switch prong with incompatible payload types " ,
\\const Union = union(enum) {
\\ A: usize,
\\ B: isize,
\\};
\\comptime {
\\ var u = Union{ .A = 8 };
\\ switch (u) {
\\ .A, .B => |e| unreachable,
\\ }
\\}
,
" tmp.zig:8:20: error: capture group with incompatible types " ,
" tmp.zig:8:9: note: type 'usize' here " ,
" tmp.zig:8:13: note: type 'isize' here " ,
) ;
2019-07-02 13:52:55 -07:00
cases . add (
" wrong type to @hasField " ,
\\export fn entry() bool {
\\ return @hasField(i32, "hi");
\\}
,
" tmp.zig:2:22: error: type 'i32' does not support @hasField " ,
) ;
2019-06-27 09:24:13 -07:00
cases . add (
" slice passed as array init type with elems " ,
\\export fn entry() void {
\\ const x = []u8{1, 2};
\\}
,
" tmp.zig:2:15: error: expected array type or [_], found slice " ,
) ;
2019-06-09 16:24:24 -07:00
cases . add (
" slice passed as array init type " ,
\\export fn entry() void {
\\ const x = []u8{};
\\}
,
2019-06-27 09:24:13 -07:00
" tmp.zig:2:15: error: expected array type or [_], found slice " ,
2019-06-09 16:24:24 -07:00
) ;
cases . add (
" inferred array size invalid here " ,
\\export fn entry() void {
\\ const x = [_]u8;
\\}
,
" tmp.zig:2:15: error: inferred array size invalid here " ,
) ;
cases . add (
" initializing array with struct syntax " ,
\\export fn entry() void {
\\ const x = [_]u8{ .y = 2 };
\\}
,
" tmp.zig:2:15: error: initializing array with struct syntax " ,
) ;
2019-05-30 12:35:30 -07:00
cases . add (
" compile error in struct init expression " ,
\\const Foo = struct {
\\ a: i32 = crap,
\\ b: i32,
\\};
\\export fn entry() void {
\\ var x = Foo{
\\ .b = 5,
\\ };
\\}
,
" tmp.zig:2:14: error: use of undeclared identifier 'crap' " ,
) ;
2019-05-27 08:39:56 -07:00
cases . add (
" undefined as field type is rejected " ,
\\const Foo = struct {
\\ a: undefined,
\\};
2019-06-25 15:06:03 -07:00
\\export fn entry1() void {
2019-05-27 08:39:56 -07:00
\\ const foo: Foo = undefined;
\\}
,
2019-08-26 11:01:59 -07:00
" tmp.zig:2:8: error: use of undefined value here causes undefined behavior " ,
2019-05-27 08:39:56 -07:00
) ;
2019-05-26 13:21:03 -07:00
cases . add (
" @hasDecl with non-container " ,
\\export fn entry() void {
\\ _ = @hasDecl(i32, "hi");
\\}
,
" tmp.zig:2:18: error: expected struct, enum, or union; found 'i32' " ,
) ;
2019-05-14 18:21:59 -07:00
cases . add (
" field access of slices " ,
\\export fn entry() void {
\\ var slice: []i32 = undefined;
\\ const info = @typeOf(slice).unknown;
\\}
,
" tmp.zig:3:32: error: type '[]i32' does not support field access " ,
) ;
2019-05-10 13:57:37 -07:00
cases . add (
" peer cast then implicit cast const pointer to mutable C pointer " ,
\\export fn func() void {
\\ var strValue: [*c]u8 = undefined;
2019-11-19 17:29:08 -08:00
\\ strValue = strValue orelse "";
2019-05-10 13:57:37 -07:00
\\}
,
2019-11-23 23:14:21 -08:00
" tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8' " ,
2019-11-20 13:08:01 -08:00
" tmp.zig:3:32: note: cast discards const qualifier " ,
2019-05-10 13:57:37 -07:00
) ;
2019-05-10 10:28:13 -07:00
cases . add (
" overflow in enum value allocation " ,
\\const Moo = enum(u8) {
\\ Last = 255,
\\ Over,
\\};
\\pub fn main() void {
\\ var y = Moo.Last;
\\}
,
" tmp.zig:3:5: error: enumeration value 256 too large for type 'u8' " ,
) ;
2019-05-09 10:18:13 -07:00
cases . add (
" attempt to cast enum literal to error " ,
\\export fn entry() void {
\\ switch (error.Hi) {
\\ .Hi => {},
\\ }
\\}
,
" tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)' " ,
) ;
2019-04-24 19:31:53 -07:00
cases . add (
" @sizeOf bad type " ,
2019-08-29 19:44:07 -07:00
\\export fn entry() usize {
\\ return @sizeOf(@typeOf(null));
2019-04-24 19:31:53 -07:00
\\}
,
2019-08-29 19:44:07 -07:00
" tmp.zig:2:20: error: no size available for type '(null)' " ,
2019-04-24 19:31:53 -07:00
) ;
2019-04-06 18:36:10 -07:00
cases . add (
2019-08-26 19:38:45 -07:00
" generic function where return type is self-referenced " ,
2019-04-06 18:36:10 -07:00
\\fn Foo(comptime T: type) Foo(T) {
\\ return struct{ x: T };
\\}
\\export fn entry() void {
\\ const t = Foo(u32) {
\\ .x = 1
\\ };
\\}
,
" tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:5:18: note: referenced here " ,
2019-04-06 18:36:10 -07:00
) ;
2019-03-25 09:55:45 -07:00
cases . add (
" @ptrToInt 0 to non optional pointer " ,
\\export fn entry() void {
\\ var b = @intToPtr(*i32, 0);
\\}
,
" tmp.zig:2:13: error: pointer type '*i32' does not allow address zero " ,
) ;
2019-03-24 15:51:24 -07:00
cases . add (
" cast enum literal to enum but it doesn't match " ,
\\const Foo = enum {
\\ a,
\\ b,
\\};
\\export fn entry() void {
\\ const x: Foo = .c;
\\}
,
" tmp.zig:6:20: error: enum 'Foo' has no field named 'c' " ,
" tmp.zig:1:13: note: 'Foo' declared here " ,
) ;
2019-03-23 16:33:00 -07:00
cases . add (
" discarding error value " ,
\\export fn entry() void {
\\ _ = foo();
\\}
\\fn foo() !void {
\\ return error.OutOfMemory;
\\}
,
2019-08-02 13:09:40 -07:00
" tmp.zig:2:12: error: error is discarded " ,
2019-03-23 16:33:00 -07:00
) ;
2019-03-20 16:00:23 -07:00
cases . add (
" volatile on global assembly " ,
\\comptime {
\\ asm volatile ("");
\\}
,
" tmp.zig:2:9: error: volatile is meaningless on global assembly " ,
) ;
2019-03-15 21:23:18 -07:00
cases . add (
" invalid multiple dereferences " ,
\\export fn a() void {
\\ var box = Box{ .field = 0 };
\\ box.*.field = 1;
\\}
\\export fn b() void {
\\ var box = Box{ .field = 0 };
\\ var boxPtr = &box;
\\ boxPtr.*.*.field = 1;
\\}
\\pub const Box = struct {
\\ field: i32,
\\};
,
" tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box' " ,
" tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box' " ,
) ;
2019-03-15 20:52:11 -07:00
cases . add (
2019-03-15 21:18:10 -07:00
" usingnamespace with wrong type " ,
2019-07-19 13:56:44 -07:00
\\usingnamespace void;
2019-03-15 21:18:10 -07:00
,
2019-05-29 13:31:49 -07:00
" tmp.zig:1:1: error: expected struct, enum, or union; found 'void' " ,
2019-03-15 21:18:10 -07:00
) ;
cases . add (
2019-03-15 20:52:11 -07:00
" ignored expression in while continuation " ,
\\export fn a() void {
\\ while (true) : (bad()) {}
\\}
\\export fn b() void {
\\ var x: anyerror!i32 = 1234;
\\ while (x) |_| : (bad()) {} else |_| {}
\\}
\\export fn c() void {
\\ var x: ?i32 = 1234;
\\ while (x) |_| : (bad()) {}
\\}
\\fn bad() anyerror!void {
\\ return error.Bad;
\\}
,
" tmp.zig:2:24: error: expression value is ignored " ,
" tmp.zig:6:25: error: expression value is ignored " ,
" tmp.zig:10:25: error: expression value is ignored " ,
) ;
2019-06-08 07:58:11 -07:00
cases . add (
" empty while loop body " ,
\\export fn a() void {
\\ while(true);
\\}
,
" tmp.zig:2:16: error: expected loop body, found ';' " ,
) ;
cases . add (
" empty for loop body " ,
\\export fn a() void {
\\ for(undefined) |x|;
\\}
,
" tmp.zig:2:23: error: expected loop body, found ';' " ,
) ;
cases . add (
" empty if body " ,
\\export fn a() void {
\\ if(true);
\\}
,
" tmp.zig:2:13: error: expected if body, found ';' " ,
) ;
2019-03-02 07:38:27 -08:00
cases . add (
" import outside package path " ,
\\comptime{
\\ _ = @import("../a.zig");
\\}
,
" tmp.zig:2:9: error: import of file outside package path: '../a.zig' " ,
) ;
2019-03-01 12:35:29 -08:00
cases . add (
" bogus compile var " ,
\\const x = @import("builtin").bogus;
\\export fn entry() usize { return @sizeOf(@typeOf(x)); }
,
" tmp.zig:1:29: error: container 'builtin' has no member called 'bogus' " ,
) ;
cases . add (
" wrong panic signature, runtime function " ,
\\test "" {}
\\
\\pub fn panic() void {}
\\
,
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
`@import("std").builtin`. The target-related types are moved
to `std.Target`. This allows the data types to have methods, such as
`std.Target.current.isDarwin()`.
* `std.os.windows.subsystem` is moved to
`std.Target.current.subsystem`.
* Remove the concept of the panic package from the compiler
implementation. Instead, `std.builtin.panic` is always the panic
function. It checks for `@hasDecl(@import("root"), "panic")`,
or else provides a default implementation.
This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 15:43:24 -07:00
" error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void' " ,
2019-03-01 12:35:29 -08:00
) ;
cases . add (
" wrong panic signature, generic function " ,
\\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
\\ while (true) {}
\\}
,
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
`@import("std").builtin`. The target-related types are moved
to `std.Target`. This allows the data types to have methods, such as
`std.Target.current.isDarwin()`.
* `std.os.windows.subsystem` is moved to
`std.Target.current.subsystem`.
* Remove the concept of the panic package from the compiler
implementation. Instead, `std.builtin.panic` is always the panic
function. It checks for `@hasDecl(@import("root"), "panic")`,
or else provides a default implementation.
This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 15:43:24 -07:00
" error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,var)var' " ,
" note: only one of the functions is generic " ,
2019-03-01 12:35:29 -08:00
) ;
cases . add (
" direct struct loop " ,
\\const A = struct { a : A, };
\\export fn entry() usize { return @sizeOf(A); }
,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:11: error: struct 'A' depends on itself " ,
2019-03-01 12:35:29 -08:00
) ;
cases . add (
" indirect struct loop " ,
\\const A = struct { b : B, };
\\const B = struct { c : C, };
\\const C = struct { a : A, };
\\export fn entry() usize { return @sizeOf(A); }
,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:11: error: struct 'A' depends on itself " ,
2019-03-01 12:35:29 -08:00
) ;
cases . add (
" instantiating an undefined value for an invalid struct that contains itself " ,
\\const Foo = struct {
\\ x: Foo,
\\};
\\
\\var foo: Foo = undefined;
\\
\\export fn entry() usize {
\\ return @sizeOf(@typeOf(foo.x));
\\}
,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:13: error: struct 'Foo' depends on itself " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:8:28: note: referenced here " ,
) ;
2019-02-28 07:11:32 -08:00
cases . add (
" @typeInfo causing depend on itself compile error " ,
\\const start = struct {
\\ fn crash() bug() {
\\ return bug;
\\ }
\\};
\\fn bug() void {
\\ _ = @typeInfo(start).Struct;
\\}
\\export fn entry() void {
\\ var boom = start.crash();
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:7:9: error: dependency loop detected " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:2:19: note: referenced here " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:10:21: note: referenced here " ,
2019-02-28 07:11:32 -08:00
) ;
cases . add (
" enum field value references enum " ,
\\pub const Foo = extern enum {
\\ A = Foo.B,
\\ C = D,
\\};
\\export fn entry() void {
\\ var s: Foo = Foo.E;
\\}
,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:17: error: enum 'Foo' depends on itself " ,
2019-02-28 07:11:32 -08:00
) ;
cases . add (
" top level decl dependency loop " ,
\\const a : @typeOf(b) = 0;
\\const b : @typeOf(a) = 0;
\\export fn entry() void {
\\ const c = a + b;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:19: error: dependency loop detected " ,
" tmp.zig:1:19: note: referenced here " ,
" tmp.zig:4:15: note: referenced here " ,
2019-02-28 07:11:32 -08:00
) ;
2019-02-26 16:41:36 -08:00
cases . addTest (
" not an enum type " ,
\\export fn entry() void {
\\ var self: Error = undefined;
\\ switch (self) {
\\ InvalidToken => |x| return x.token,
\\ ExpectedVarDeclOrFn => |x| return x.token,
\\ }
\\}
\\const Error = union(enum) {
\\ A: InvalidToken,
\\ B: ExpectedVarDeclOrFn,
\\};
\\const InvalidToken = struct {};
\\const ExpectedVarDeclOrFn = struct {};
,
2019-03-23 22:15:21 -07:00
" tmp.zig:4:9: error: expected type '@TagType(Error)', found 'type' " ,
2019-02-26 16:41:36 -08:00
) ;
2019-02-26 16:34:22 -08:00
cases . addTest (
" binary OR operator on error sets " ,
\\pub const A = error.A;
\\pub const AB = A | error.B;
\\export fn entry() void {
\\ var x: AB = undefined;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}' " ,
2019-02-26 16:34:22 -08:00
) ;
2019-02-25 18:46:32 -08:00
if ( builtin . os = = builtin . Os . linux ) {
cases . addTest (
" implicit dependency on libc " ,
\\extern "c" fn exit(u8) void;
\\export fn entry() void {
\\ exit(0);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: dependency on library c must be explicitly specified in the build command " ,
2019-02-25 18:46:32 -08:00
) ;
2019-02-25 17:09:18 -08:00
2019-02-25 18:46:32 -08:00
cases . addTest (
" libc headers note " ,
\\const c = @cImport(@cInclude("stdio.h"));
\\export fn entry() void {
2019-11-19 17:29:08 -08:00
\\ _ = c.printf("hello, world!\n");
2019-02-25 18:46:32 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:11: error: C import failed " ,
" tmp.zig:1:11: note: libc headers not available; compilation does not link against libc " ,
2019-02-25 18:46:32 -08:00
) ;
}
2019-02-25 16:31:30 -08:00
2019-02-22 10:28:57 -08:00
cases . addTest (
" comptime vector overflow shows the index " ,
\\comptime {
2019-06-09 16:24:24 -07:00
\\ var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };
\\ var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };
2019-02-22 10:28:57 -08:00
\\ var x = a + b;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:15: error: operation caused overflow " ,
" tmp.zig:4:15: note: when computing vector element at index 2 " ,
2019-02-22 10:28:57 -08:00
) ;
2019-02-21 11:44:14 -08:00
cases . addTest (
" packed struct with fields of not allowed types " ,
\\const A = packed struct {
\\ x: anyerror,
\\};
\\const B = packed struct {
\\ x: [2]u24,
\\};
\\const C = packed struct {
\\ x: [1]anyerror,
\\};
\\const D = packed struct {
\\ x: [1]S,
\\};
\\const E = packed struct {
\\ x: [1]U,
\\};
\\const F = packed struct {
\\ x: ?anyerror,
\\};
\\const G = packed struct {
\\ x: Enum,
\\};
2019-06-25 15:06:03 -07:00
\\export fn entry1() void {
2019-02-21 11:44:14 -08:00
\\ var a: A = undefined;
2019-06-25 15:06:03 -07:00
\\}
\\export fn entry2() void {
2019-02-21 11:44:14 -08:00
\\ var b: B = undefined;
2019-06-25 15:06:03 -07:00
\\}
\\export fn entry3() void {
2019-02-21 11:44:14 -08:00
\\ var r: C = undefined;
2019-06-25 15:06:03 -07:00
\\}
\\export fn entry4() void {
2019-02-21 11:44:14 -08:00
\\ var d: D = undefined;
2019-06-25 15:06:03 -07:00
\\}
\\export fn entry5() void {
2019-02-21 11:44:14 -08:00
\\ var e: E = undefined;
2019-06-25 15:06:03 -07:00
\\}
\\export fn entry6() void {
2019-02-21 11:44:14 -08:00
\\ var f: F = undefined;
2019-06-25 15:06:03 -07:00
\\}
\\export fn entry7() void {
2019-02-21 11:44:14 -08:00
\\ var g: G = undefined;
\\}
\\const S = struct {
\\ x: i32,
\\};
\\const U = struct {
\\ A: i32,
\\ B: u32,
\\};
\\const Enum = enum {
\\ A,
\\ B,
\\};
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation " ,
" tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits " ,
" tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation " ,
" tmp.zig:11:5: error: non-packed, non-extern struct 'S' not allowed in packed struct; no guaranteed in-memory representation " ,
" tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation " ,
" tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation " ,
" tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation " ,
2019-06-25 15:06:03 -07:00
" tmp.zig:50:14: note: enum declaration does not specify an integer tag type " ,
2019-02-21 11:44:14 -08:00
) ;
2019-02-20 05:04:46 -08:00
cases . addCase ( x : {
var tc = cases . create (
" deduplicate undeclared identifier " ,
\\export fn a() void {
\\ x += 1;
\\}
\\export fn b() void {
\\ x += 1;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: use of undeclared identifier 'x' " ,
2019-02-20 05:04:46 -08:00
) ;
tc . expect_exact = true ;
break : x tc ;
} ) ;
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-18 15:11:30 -08:00
" export generic function " ,
\\export fn foo(num: var) i32 {
\\ return 0;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'ccc' " ,
2019-02-18 15:11:30 -08:00
) ;
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-14 20:09:12 -08:00
" C pointer to c_void " ,
\\export fn a() void {
\\ var x: *c_void = undefined;
\\ var y: [*c]c_void = x;
\\}
,
2019-08-26 15:35:36 -07:00
" tmp.zig:3:16: error: C pointers cannot point opaque types " ,
2019-02-14 20:09:12 -08:00
) ;
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-14 10:07:51 -08:00
" directly embedding opaque type in struct and union " ,
\\const O = @OpaqueType();
\\const Foo = struct {
\\ o: O,
\\};
\\const Bar = union {
\\ One: i32,
\\ Two: O,
\\};
\\export fn a() void {
\\ var foo: Foo = undefined;
\\}
\\export fn b() void {
\\ var bar: Bar = undefined;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:8: error: opaque types have unknown size and therefore cannot be directly embedded in structs " ,
" tmp.zig:7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions " ,
2019-02-14 10:07:51 -08:00
) ;
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-14 09:28:50 -08:00
" implicit cast between C pointer and Zig pointer - bad const/align/child " ,
\\export fn a() void {
\\ var x: [*c]u8 = undefined;
\\ var y: *align(4) u8 = x;
\\}
\\export fn b() void {
\\ var x: [*c]const u8 = undefined;
\\ var y: *u8 = x;
\\}
\\export fn c() void {
\\ var x: [*c]u8 = undefined;
\\ var y: *u32 = x;
\\}
\\export fn d() void {
\\ var y: *align(1) u32 = undefined;
\\ var x: [*c]u32 = y;
\\}
\\export fn e() void {
\\ var y: *const u8 = undefined;
\\ var x: [*c]u8 = y;
\\}
\\export fn f() void {
\\ var y: *u8 = undefined;
\\ var x: [*c]u32 = y;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:27: error: cast increases pointer alignment " ,
" tmp.zig:7:18: error: cast discards const qualifier " ,
" tmp.zig:11:19: error: expected type '*u32', found '[*c]u8' " ,
" tmp.zig:11:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32' " ,
" tmp.zig:15:22: error: cast increases pointer alignment " ,
" tmp.zig:19:21: error: cast discards const qualifier " ,
" tmp.zig:23:22: error: expected type '[*c]u32', found '*u8' " ,
2019-02-14 09:28:50 -08:00
) ;
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-13 21:40:39 -08:00
" implicit casting null c pointer to zig pointer " ,
\\comptime {
\\ var c_ptr: [*c]u8 = 0;
\\ var zig_ptr: *u8 = c_ptr;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:24: error: null pointer casted to type '*u8' " ,
2019-02-13 21:40:39 -08:00
) ;
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-13 21:40:39 -08:00
" implicit casting undefined c pointer to zig pointer " ,
\\comptime {
\\ var c_ptr: [*c]u8 = undefined;
\\ var zig_ptr: *u8 = c_ptr;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:24: error: use of undefined value here causes undefined behavior " ,
2019-02-13 21:40:39 -08:00
) ;
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-12 15:20:00 -08:00
" implicit casting C pointers which would mess up null semantics " ,
\\export fn entry() void {
\\ var slice: []const u8 = "aoeu";
\\ const opt_many_ptr: [*]const u8 = slice.ptr;
\\ var ptr_opt_many_ptr = &opt_many_ptr;
\\ var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
\\ ptr_opt_many_ptr = c_ptr;
\\}
\\export fn entry2() void {
2019-11-20 13:08:01 -08:00
\\ var buf: [4]u8 = "aoeu".*;
2019-02-12 15:20:00 -08:00
\\ var slice: []u8 = &buf;
\\ var opt_many_ptr: [*]u8 = slice.ptr;
\\ var ptr_opt_many_ptr = &opt_many_ptr;
2019-02-14 12:48:28 -08:00
\\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr;
2019-02-12 15:20:00 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8' " ,
" tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8' " ,
" tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8' " ,
" tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8' " ,
" tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8' " ,
" tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8' " ,
2019-02-12 15:20:00 -08:00
) ;
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-12 07:25:21 -08:00
" implicit casting too big integers to C pointers " ,
\\export fn a() void {
\\ var ptr: [*c]u8 = (1 << 64) + 1;
\\}
\\export fn b() void {
\\ var x: @IntType(false, 65) = 0x1234;
\\ var ptr: [*c]u8 = x;
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize' " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8' " ,
2019-02-12 07:25:21 -08:00
) ;
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-14 16:53:46 -08:00
" C pointer pointing to non C ABI compatible type or has align attr " ,
2019-02-11 21:51:06 -08:00
\\const Foo = struct {};
2019-02-14 16:53:46 -08:00
\\export fn a() void {
\\ const T = [*c]Foo;
2019-08-30 17:06:02 -07:00
\\ var t: T = undefined;
2019-02-14 16:53:46 -08:00
\\}
2019-02-11 21:51:06 -08:00
,
2019-08-26 15:35:36 -07:00
" tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo' " ,
2019-02-11 21:51:06 -08:00
) ;
2019-02-17 12:47:53 -08:00
cases . addCase ( x : {
var tc = cases . create (
" compile log statement warning deduplication in generic fn " ,
\\export fn entry() void {
\\ inner(1);
\\ inner(2);
\\}
\\fn inner(comptime n: usize) void {
\\ comptime var i = 0;
\\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:7:39: error: found compile log statement " ,
2019-02-17 12:47:53 -08:00
) ;
tc . expect_exact = true ;
break : x tc ;
} ) ;
2019-02-14 15:54:37 -08:00
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-12 21:22:16 -08:00
" assign to invalid dereference " ,
\\export fn entry() void {
\\ 'a'.* = 1;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int' " ,
2019-02-12 21:22:16 -08:00
) ;
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-12 21:22:16 -08:00
" take slice of invalid dereference " ,
\\export fn entry() void {
\\ const x = 'a'.*[0..];
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int' " ,
2019-02-12 21:22:16 -08:00
) ;
2019-08-26 15:35:36 -07:00
cases . add (
2019-02-09 18:10:59 -08:00
" @truncate undefined value " ,
\\export fn entry() void {
2019-11-06 20:25:57 -08:00
\\ var z = @truncate(u8, @as(u16, undefined));
2019-02-09 18:10:59 -08:00
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:27: error: use of undefined value here causes undefined behavior " ,
2019-02-09 18:10:59 -08:00
) ;
2019-02-08 16:23:46 -08:00
cases . addTest (
" return invalid type from test " ,
\\test "example" { return 1; }
,
2019-11-08 12:56:21 -08:00
" tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void' " ,
2019-02-08 16:23:46 -08:00
) ;
2019-02-06 10:48:04 -08:00
cases . add (
" threadlocal qualifier on const " ,
\\threadlocal const x: i32 = 1234;
\\export fn entry() i32 {
\\ return x;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:13: error: threadlocal variable cannot be constant " ,
2019-02-06 10:48:04 -08:00
) ;
2019-02-01 11:06:51 -08:00
cases . add (
" @bitCast same size but bit count mismatch " ,
\\export fn entry(byte: u8) void {
\\ var oops = @bitCast(u7, byte);
\\}
,
2019-06-25 15:06:03 -07:00
" tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits " ,
2019-02-01 11:06:51 -08:00
) ;
2019-08-24 03:16:46 -07:00
cases . add (
" @bitCast with different sizes inside an expression " ,
\\export fn entry() void {
2019-11-07 15:52:09 -08:00
\\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
2019-08-24 03:16:46 -07:00
\\}
,
" tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4 " ,
) ;
2019-01-25 12:10:40 -08:00
cases . add (
2019-01-29 19:28:33 -08:00
" attempted `&&` " ,
\\export fn entry(a: bool, b: bool) i32 {
\\ if (a && b) {
\\ return 1234;
\\ }
\\ return 5678;
2019-01-25 12:10:40 -08:00
\\}
,
2019-08-26 09:43:36 -07:00
" tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND " ,
2019-01-25 12:10:40 -08:00
) ;
cases . add (
2019-01-29 19:28:33 -08:00
" attempted `||` on boolean values " ,
\\export fn entry(a: bool, b: bool) i32 {
\\ if (a || b) {
\\ return 1234;
\\ }
\\ return 5678;
2019-01-25 12:10:40 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:9: error: expected error set type, found 'bool' " ,
" tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR " ,
2019-01-25 12:10:40 -08:00
) ;
2019-01-20 11:09:17 -08:00
cases . add (
" compile log a pointer to an opaque value " ,
\\export fn entry() void {
\\ @compileLog(@ptrCast(*const c_void, &entry));
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: found compile log statement " ,
2019-01-20 11:09:17 -08:00
) ;
2018-12-27 11:46:32 -08:00
cases . add (
" duplicate boolean switch value " ,
\\comptime {
\\ const x = switch (true) {
\\ true => false,
\\ false => true,
\\ true => false,
\\ };
\\}
\\comptime {
\\ const x = switch (true) {
\\ false => true,
\\ true => false,
\\ false => true,
\\ };
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:9: error: duplicate switch value " ,
" tmp.zig:12:9: error: duplicate switch value " ,
2018-12-27 11:46:32 -08:00
) ;
cases . add (
" missing boolean switch value " ,
\\comptime {
\\ const x = switch (true) {
\\ true => false,
\\ };
\\}
\\comptime {
\\ const x = switch (true) {
\\ false => true,
\\ };
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: switch must handle all possibilities " ,
" tmp.zig:7:15: error: switch must handle all possibilities " ,
2018-12-27 11:46:32 -08:00
) ;
2018-12-12 17:19:46 -08:00
cases . add (
" reading past end of pointer casted array " ,
\\comptime {
2019-11-20 13:08:01 -08:00
\\ const array: [4]u8 = "aoeu".*;
2019-02-20 19:40:41 -08:00
\\ const slice = array[1..];
2018-12-12 17:19:46 -08:00
\\ const int_ptr = @ptrCast(*const u24, slice.ptr);
\\ const deref = int_ptr.*;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes " ,
2018-12-12 17:19:46 -08:00
) ;
2018-12-05 12:32:25 -08:00
cases . add (
" error note for function parameter incompatibility " ,
\\fn do_the_thing(func: fn (arg: i32) void) void {}
\\fn bar(arg: bool) void {}
\\export fn entry() void {
\\ do_the_thing(bar);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void " ,
" tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32' " ,
2018-12-05 12:32:25 -08:00
) ;
2018-11-18 16:36:27 -08:00
cases . add (
" cast negative value to unsigned integer " ,
\\comptime {
\\ const value: i32 = -1;
\\ const unsigned = @intCast(u32, value);
\\}
\\export fn entry1() void {
\\ const value: i32 = -1;
\\ const unsigned: u32 = value;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:36: error: cannot cast negative value -1 to unsigned integer type 'u32' " ,
" tmp.zig:7:27: error: cannot cast negative value -1 to unsigned integer type 'u32' " ,
2018-11-18 16:36:27 -08:00
) ;
cases . add (
" integer cast truncates bits " ,
\\export fn entry1() void {
\\ const spartan_count: u16 = 300;
\\ const byte = @intCast(u8, spartan_count);
\\}
\\export fn entry2() void {
\\ const spartan_count: u16 = 300;
\\ const byte: u8 = spartan_count;
\\}
\\export fn entry3() void {
\\ var spartan_count: u16 = 300;
\\ var byte: u8 = spartan_count;
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8' " ,
" tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8' " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:11:20: error: expected type 'u8', found 'u16' " ,
2018-11-18 16:36:27 -08:00
) ;
cases . add (
" comptime implicit cast f64 to f32 " ,
\\export fn entry() void {
\\ const x: f64 = 16777217;
\\ const y: f32 = x;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information " ,
2018-11-18 16:36:27 -08:00
) ;
cases . add (
" implicit cast from f64 to f32 " ,
\\var x: f64 = 1.0;
\\var y: f32 = x;
\\
\\export fn entry() usize { return @sizeOf(@typeOf(y)); }
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:14: error: expected type 'f32', found 'f64' " ,
2018-11-18 16:36:27 -08:00
) ;
2018-11-06 08:09:14 -08:00
cases . add (
" exceeded maximum bit width of integer " ,
\\export fn entry1() void {
\\ const T = @IntType(false, 65536);
\\}
\\export fn entry2() void {
\\ var x: i65536 = 1;
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16' " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535 " ,
2018-10-01 11:30:34 -07:00
) ;
2018-09-26 13:59:08 -07:00
cases . add (
" compile error when evaluating return type of inferred error set " ,
2018-11-13 05:08:37 -08:00
\\const Car = struct {
2018-09-26 13:59:08 -07:00
\\ foo: *SymbolThatDoesNotExist,
\\ pub fn init() !Car {}
\\};
\\export fn entry() void {
\\ const car = Car.init();
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist' " ,
2018-09-26 13:59:08 -07:00
) ;
2018-09-26 08:06:09 -07:00
cases . add (
" don't implicit cast double pointer to *c_void " ,
\\export fn entry() void {
\\ var a: u32 = 1;
\\ var ptr: *c_void = &a;
\\ var b: *u32 = @ptrCast(*u32, ptr);
\\ var ptr2: *c_void = &b;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:26: error: expected type '*c_void', found '**u32' " ,
2018-09-26 08:06:09 -07:00
) ;
2018-09-25 09:03:39 -07:00
cases . add (
" runtime index into comptime type slice " ,
2018-11-13 05:08:37 -08:00
\\const Struct = struct {
2018-09-25 09:03:39 -07:00
\\ a: u32,
\\};
\\fn getIndex() usize {
\\ return 2;
\\}
\\export fn entry() void {
\\ const index = getIndex();
\\ const field = @typeInfo(Struct).Struct.fields[index];
\\}
,
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
`@import("std").builtin`. The target-related types are moved
to `std.Target`. This allows the data types to have methods, such as
`std.Target.current.isDarwin()`.
* `std.os.windows.subsystem` is moved to
`std.Target.current.subsystem`.
* Remove the concept of the panic package from the compiler
implementation. Instead, `std.builtin.panic` is always the panic
function. It checks for `@hasDecl(@import("root"), "panic")`,
or else provides a default implementation.
This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 15:43:24 -07:00
" tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known " ,
2018-09-25 09:03:39 -07:00
) ;
2018-09-22 07:46:22 -07:00
cases . add (
" compile log statement inside function which must be comptime evaluated " ,
\\fn Foo(comptime T: type) type {
\\ @compileLog(@typeName(T));
\\ return T;
\\}
\\export fn entry() void {
\\ _ = Foo(i32);
\\ _ = @typeName(Foo(i32));
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: found compile log statement " ,
2018-09-22 07:46:22 -07:00
) ;
2018-09-22 07:04:47 -07:00
cases . add (
" comptime slice of an undefined slice " ,
\\comptime {
\\ var a: []u8 = undefined;
\\ var b = a[0..10];
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:14: error: slice of undefined " ,
2018-09-22 07:04:47 -07:00
) ;
2018-09-20 09:24:51 -07:00
cases . add (
" implicit cast const array to mutable slice " ,
\\export fn entry() void {
2019-06-09 16:24:24 -07:00
\\ const buffer: [1]u8 = [_]u8{8};
2018-09-20 09:24:51 -07:00
\\ const sliceA: []u8 = &buffer;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8' " ,
2018-09-20 09:24:51 -07:00
) ;
2018-09-18 13:32:40 -07:00
cases . add (
" deref slice and get len field " ,
\\export fn entry() void {
\\ var a: []u8 = undefined;
\\ _ = a.*.len;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8' " ,
2018-09-18 13:32:40 -07:00
) ;
2018-09-17 16:41:11 -07:00
cases . add (
" @ptrCast a 0 bit type to a non- 0 bit type " ,
\\export fn entry() bool {
\\ var x: u0 = 0;
\\ const p = @ptrCast(?*u0, &x);
\\ return p == null;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation " ,
" tmp.zig:3:31: note: '*u0' has no in-memory bits " ,
" tmp.zig:3:24: note: '?*u0' has in-memory bits " ,
2018-09-17 16:41:11 -07:00
) ;
2018-09-17 15:58:50 -07:00
cases . add (
" comparing a non-optional pointer against null " ,
\\export fn entry() void {
\\ var x: i32 = 1;
\\ _ = &x == null;
\\}
,
2019-05-08 13:06:34 -07:00
" tmp.zig:3:12: error: comparison of '*i32' with null " ,
2018-09-17 15:58:50 -07:00
) ;
2018-09-13 10:48:41 -07:00
cases . add (
" non error sets used in merge error sets operator " ,
\\export fn foo() void {
\\ const Errors = u8 || u16;
\\}
\\export fn bar() void {
2018-11-13 05:08:37 -08:00
\\ const Errors = error{} || u16;
2018-09-13 10:48:41 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:20: error: expected error set type, found type 'u8' " ,
" tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR " ,
" tmp.zig:5:31: error: expected error set type, found type 'u16' " ,
" tmp.zig:5:28: note: `||` merges error sets; `or` performs boolean OR " ,
2018-09-13 10:48:41 -07:00
) ;
2018-09-07 12:17:24 -07:00
cases . add (
" variable initialization compile error then referenced " ,
\\fn Undeclared() type {
\\ return T;
\\}
\\fn Gen() type {
\\ const X = Undeclared();
2018-11-13 05:08:37 -08:00
\\ return struct {
2018-09-07 12:17:24 -07:00
\\ x: X,
\\ };
\\}
\\export fn entry() void {
\\ const S = Gen();
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:12: error: use of undeclared identifier 'T' " ,
2018-09-07 12:17:24 -07:00
) ;
2018-09-05 17:32:06 -07:00
cases . add (
2018-09-05 18:21:59 -07:00
" refer to the type of a generic function " ,
\\export fn entry() void {
\\ const Func = fn (type) void;
\\ const f: Func = undefined;
\\ f(i32);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:5: error: use of undefined value here causes undefined behavior " ,
2018-09-05 18:21:59 -07:00
) ;
cases . add (
2018-09-05 17:32:06 -07:00
" accessing runtime parameter from outer function " ,
\\fn outer(y: u32) fn (u32) u32 {
2018-11-13 05:08:37 -08:00
\\ const st = struct {
2018-09-05 17:32:06 -07:00
\\ fn get(z: u32) u32 {
\\ return z + y;
\\ }
\\ };
\\ return st.get;
\\}
\\export fn entry() void {
\\ var func = outer(10);
\\ var x = func(3);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:24: error: 'y' not accessible from inner function " ,
" tmp.zig:3:28: note: crossed function definition here " ,
" tmp.zig:1:10: note: declared here " ,
2018-09-05 17:32:06 -07:00
) ;
2018-09-05 15:01:48 -07:00
cases . add (
" non int passed to @intToFloat " ,
\\export fn entry() void {
\\ const x = @intToFloat(f32, 1.1);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:32: error: expected int type, found 'comptime_float' " ,
2018-09-05 15:01:48 -07:00
) ;
cases . add (
" non float passed to @floatToInt " ,
\\export fn entry() void {
2019-11-06 20:25:57 -08:00
\\ const x = @floatToInt(i32, @as(i32, 54));
2018-09-05 15:01:48 -07:00
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:32: error: expected float type, found 'i32' " ,
2018-09-05 15:01:48 -07:00
) ;
cases . add (
" out of range comptime_int passed to @floatToInt " ,
\\export fn entry() void {
\\ const x = @floatToInt(i8, 200);
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8' " ,
2018-09-05 15:01:48 -07:00
) ;
2018-09-05 12:53:36 -07:00
cases . add (
" load too many bytes from comptime reinterpreted pointer " ,
\\export fn entry() void {
\\ const float: f32 = 5.99999999999994648725e-01;
\\ const float_ptr = &float;
\\ const int_ptr = @ptrCast(*const i64, float_ptr);
\\ const int_val = int_ptr.*;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes " ,
2018-09-05 12:53:36 -07:00
) ;
2018-09-05 07:43:35 -07:00
cases . add (
" invalid type used in array type " ,
2018-11-13 05:08:37 -08:00
\\const Item = struct {
2018-09-05 07:43:35 -07:00
\\ field: SomeNonexistentType,
\\};
\\var items: [100]Item = undefined;
\\export fn entry() void {
\\ const a = items[0];
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType' " ,
2018-09-05 07:43:35 -07:00
) ;
2018-09-04 14:38:48 -07:00
cases . add (
" @noInlineCall on an inline function " ,
\\inline fn foo() void {}
\\
\\export fn entry() void {
\\ @noInlineCall(foo);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:5: error: no-inline call of inline function " ,
2018-09-04 14:38:48 -07:00
) ;
2019-07-02 18:14:42 -07:00
cases . add (
" comptime continue inside runtime catch " ,
\\export fn entry(c: bool) void {
\\ const ints = [_]u8{ 1, 2 };
\\ inline for (ints) |_| {
\\ bad() catch |_| continue;
\\ }
\\}
\\fn bad() !void {
\\ return error.Bad;
\\}
,
" tmp.zig:4:25: error: comptime control flow inside runtime block " ,
" tmp.zig:4:15: note: runtime block created here " ,
) ;
2018-09-04 12:28:13 -07:00
cases . add (
" comptime continue inside runtime switch " ,
\\export fn entry() void {
\\ var p: i32 = undefined;
\\ comptime var q = true;
\\ inline while (q) {
\\ switch (p) {
\\ 11 => continue,
\\ else => {},
\\ }
\\ q = false;
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:19: error: comptime control flow inside runtime block " ,
" tmp.zig:5:9: note: runtime block created here " ,
2018-09-04 12:28:13 -07:00
) ;
cases . add (
" comptime continue inside runtime while error " ,
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ var p: anyerror!usize = undefined;
2018-09-04 12:28:13 -07:00
\\ comptime var q = true;
\\ outer: inline while (q) {
\\ while (p) |_| {
\\ continue :outer;
\\ } else |_| {}
\\ q = false;
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:13: error: comptime control flow inside runtime block " ,
" tmp.zig:5:9: note: runtime block created here " ,
2018-09-04 12:28:13 -07:00
) ;
cases . add (
" comptime continue inside runtime while optional " ,
\\export fn entry() void {
\\ var p: ?usize = undefined;
\\ comptime var q = true;
\\ outer: inline while (q) {
\\ while (p) |_| continue :outer;
\\ q = false;
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:23: error: comptime control flow inside runtime block " ,
" tmp.zig:5:9: note: runtime block created here " ,
2018-09-04 12:28:13 -07:00
) ;
cases . add (
" comptime continue inside runtime while bool " ,
\\export fn entry() void {
\\ var p: usize = undefined;
\\ comptime var q = true;
\\ outer: inline while (q) {
\\ while (p == 11) continue :outer;
\\ q = false;
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:25: error: comptime control flow inside runtime block " ,
" tmp.zig:5:9: note: runtime block created here " ,
2018-09-04 12:28:13 -07:00
) ;
cases . add (
" comptime continue inside runtime if error " ,
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ var p: anyerror!i32 = undefined;
2018-09-04 12:28:13 -07:00
\\ comptime var q = true;
\\ inline while (q) {
\\ if (p) |_| continue else |_| {}
\\ q = false;
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:20: error: comptime control flow inside runtime block " ,
" tmp.zig:5:9: note: runtime block created here " ,
2018-09-04 12:28:13 -07:00
) ;
cases . add (
" comptime continue inside runtime if optional " ,
\\export fn entry() void {
\\ var p: ?i32 = undefined;
\\ comptime var q = true;
\\ inline while (q) {
\\ if (p) |_| continue;
\\ q = false;
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:20: error: comptime control flow inside runtime block " ,
" tmp.zig:5:9: note: runtime block created here " ,
2018-09-04 12:28:13 -07:00
) ;
cases . add (
" comptime continue inside runtime if bool " ,
\\export fn entry() void {
\\ var p: usize = undefined;
\\ comptime var q = true;
\\ inline while (q) {
\\ if (p == 11) continue;
\\ q = false;
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:22: error: comptime control flow inside runtime block " ,
" tmp.zig:5:9: note: runtime block created here " ,
2018-09-04 12:28:13 -07:00
) ;
2018-08-28 12:48:39 -07:00
cases . add (
" switch with invalid expression parameter " ,
\\export fn entry() void {
\\ Test(i32);
\\}
\\fn Test(comptime T: type) void {
\\ const x = switch (T) {
\\ []u8 => |x| 123,
\\ i32 => |x| 456,
\\ else => unreachable,
\\ };
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:7:17: error: switch on type 'type' provides no expression parameter " ,
2018-08-28 12:48:39 -07:00
) ;
2018-08-28 12:39:32 -07:00
cases . add (
" function protoype with no body " ,
\\fn foo() void;
\\export fn entry() void {
\\ foo();
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:1: error: non-extern function has no body " ,
2018-08-28 12:39:32 -07:00
) ;
2018-08-02 11:15:31 -07:00
cases . add (
2019-08-11 16:53:10 -07:00
" @frame() called outside of function definition " ,
\\var handle_undef: anyframe = undefined;
\\var handle_dummy: anyframe = @frame();
2018-08-02 11:15:31 -07:00
\\export fn entry() bool {
\\ return handle_undef == handle_dummy;
\\}
,
2019-08-11 16:53:10 -07:00
" tmp.zig:2:30: error: @frame() called outside of function definition " ,
2018-08-02 11:15:31 -07:00
) ;
2018-08-02 10:55:31 -07:00
cases . add (
" `_` is not a declarable symbol " ,
\\export fn f1() usize {
\\ var _: usize = 2;
\\ return _;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: `_` is not a declarable symbol " ,
2018-08-02 10:55:31 -07:00
) ;
cases . add (
" `_` should not be usable inside for " ,
\\export fn returns() void {
2019-06-09 16:24:24 -07:00
\\ for ([_]void{}) |_, i| {
\\ for ([_]void{}) |_, j| {
2018-08-02 10:55:31 -07:00
\\ return _;
\\ }
\\ }
\\}
,
2019-05-28 15:18:52 -07:00
" tmp.zig:4:20: error: `_` may only be used to assign things to " ,
2018-08-02 10:55:31 -07:00
) ;
cases . add (
" `_` should not be usable inside while " ,
\\export fn returns() void {
\\ while (optionalReturn()) |_| {
\\ while (optionalReturn()) |_| {
\\ return _;
\\ }
\\ }
\\}
\\fn optionalReturn() ?u32 {
\\ return 1;
\\}
,
2019-05-28 15:18:52 -07:00
" tmp.zig:4:20: error: `_` may only be used to assign things to " ,
2018-08-02 10:55:31 -07:00
) ;
cases . add (
" `_` should not be usable inside while else " ,
\\export fn returns() void {
\\ while (optionalReturnError()) |_| {
\\ while (optionalReturnError()) |_| {
\\ return;
\\ } else |_| {
\\ if (_ == error.optionalReturnError) return;
\\ }
\\ }
\\}
\\fn optionalReturnError() !?u32 {
\\ return error.optionalReturnError;
\\}
,
2019-05-28 15:18:52 -07:00
" tmp.zig:6:17: error: `_` may only be used to assign things to " ,
2018-08-02 10:55:31 -07:00
) ;
2018-07-26 15:29:07 -07:00
cases . add (
" while loop body expression ignored " ,
\\fn returns() usize {
\\ return 2;
\\}
\\export fn f1() void {
\\ while (true) returns();
\\}
\\export fn f2() void {
\\ var x: ?i32 = null;
\\ while (x) |_| returns();
\\}
\\export fn f3() void {
2018-11-13 05:08:37 -08:00
\\ var x: anyerror!i32 = error.Bad;
2018-07-26 15:29:07 -07:00
\\ while (x) |_| returns() else |_| unreachable;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:25: error: expression value is ignored " ,
" tmp.zig:9:26: error: expression value is ignored " ,
" tmp.zig:13:26: error: expression value is ignored " ,
2018-07-26 15:29:07 -07:00
) ;
2018-07-25 15:15:55 -07:00
cases . add (
" missing parameter name of generic function " ,
\\fn dump(var) void {}
\\export fn entry() void {
\\ var a: u8 = 9;
\\ dump(a);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:9: error: missing parameter name " ,
2018-07-25 15:15:55 -07:00
) ;
2018-07-25 14:08:55 -07:00
cases . add (
" non-inline for loop on a type that requires comptime " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2018-07-25 14:08:55 -07:00
\\ name: []const u8,
\\ T: type,
\\};
\\export fn entry() void {
\\ const xx: [2]Foo = undefined;
\\ for (xx) |f| {}
\\}
,
2019-06-25 15:06:03 -07:00
" tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known " ,
2018-07-25 14:08:55 -07:00
) ;
2018-07-24 07:13:40 -07:00
cases . add (
" generic fn as parameter without comptime keyword " ,
\\fn f(_: fn (var) void) void {}
\\fn g(_: var) void {}
\\export fn entry() void {
\\ f(g);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:9: error: parameter of type 'fn(var)var' must be declared comptime " ,
2018-07-24 07:13:40 -07:00
) ;
2018-07-16 07:53:15 -07:00
cases . add (
" optional pointer to void in extern struct " ,
2018-11-13 05:08:37 -08:00
\\const Foo = extern struct {
2018-07-11 10:23:37 -07:00
\\ x: ?*const void,
\\};
2018-11-13 05:08:37 -08:00
\\const Bar = extern struct {
2018-07-11 10:23:37 -07:00
\\ foo: Foo,
\\ y: i32,
\\};
\\export fn entry(bar: *Bar) void {}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void' " ,
2018-07-11 10:23:37 -07:00
) ;
cases . add (
" use of comptime-known undefined function value " ,
2018-11-13 05:08:37 -08:00
\\const Cmd = struct {
2018-07-11 10:23:37 -07:00
\\ exec: fn () void,
\\};
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ const command = Cmd{ .exec = undefined };
2018-07-11 10:23:37 -07:00
\\ command.exec();
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:12: error: use of undefined value here causes undefined behavior " ,
2018-07-11 10:23:37 -07:00
) ;
2018-07-10 07:12:08 -07:00
cases . add (
" use of comptime-known undefined function value " ,
2018-11-13 05:08:37 -08:00
\\const Cmd = struct {
2018-07-10 07:12:08 -07:00
\\ exec: fn () void,
\\};
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ const command = Cmd{ .exec = undefined };
2018-07-10 07:12:08 -07:00
\\ command.exec();
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:12: error: use of undefined value here causes undefined behavior " ,
2018-07-10 07:12:08 -07:00
) ;
2018-07-09 08:13:29 -07:00
cases . add (
" bad @alignCast at comptime " ,
\\comptime {
\\ const ptr = @intToPtr(*i32, 0x1);
\\ const aligned = @alignCast(4, ptr);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes " ,
2018-07-09 08:13:29 -07:00
) ;
2018-07-09 07:43:29 -07:00
cases . add (
" @ptrToInt on *void " ,
\\export fn entry() bool {
\\ return @ptrToInt(&{}) == @ptrToInt(&{});
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:23: error: pointer to size 0 type has no address " ,
2018-07-09 07:43:29 -07:00
) ;
2018-07-06 21:25:32 -07:00
cases . add (
" @popCount - non-integer " ,
\\export fn entry(x: f32) u32 {
2019-04-03 07:00:39 -07:00
\\ return @popCount(f32, x);
2018-07-06 21:25:32 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:22: error: expected integer type, found 'f32' " ,
2018-07-06 21:25:32 -07:00
) ;
2018-07-06 13:20:46 -07:00
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 {}
,
2019-11-12 14:59:24 -08:00
" tmp.zig:6:9: error: expected type '*b.Foo', found '*a.Foo' " ,
" tmp.zig:6:9: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo' " ,
2019-03-01 14:15:58 -08:00
" a.zig:1:17: note: a.Foo declared here " ,
" b.zig:1:17: note: b.Foo declared here " ,
2018-07-06 13:20:46 -07:00
) ;
tc . addSourceFile ( " a.zig " ,
2018-11-13 05:08:37 -08:00
\\pub const Foo = struct {
2018-07-06 13:20:46 -07:00
\\ x: i32,
\\};
) ;
tc . addSourceFile ( " b.zig " ,
2018-11-13 05:08:37 -08:00
\\pub const Foo = struct {
2018-07-06 13:20:46 -07:00
\\ z: f64,
\\};
) ;
break : x tc ;
} ) ;
2018-06-19 13:06:10 -07:00
cases . add (
" @floatToInt comptime safety " ,
\\comptime {
2019-11-07 15:52:09 -08:00
\\ _ = @floatToInt(i8, @as(f32, -129.1));
2018-06-19 13:06:10 -07:00
\\}
\\comptime {
2019-11-07 15:52:09 -08:00
\\ _ = @floatToInt(u8, @as(f32, -1.1));
2018-06-19 13:06:10 -07:00
\\}
\\comptime {
2019-11-07 15:52:09 -08:00
\\ _ = @floatToInt(u8, @as(f32, 256.1));
2018-06-19 13:06:10 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8' " ,
" tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8' " ,
" tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8' " ,
2018-06-19 13:06:10 -07:00
) ;
2018-06-18 08:12:15 -07:00
cases . add (
" use c_void as return type of fn ptr " ,
\\export fn entry() void {
\\ const a: fn () c_void = undefined;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:20: error: return type cannot be opaque " ,
2018-06-18 08:12:15 -07:00
) ;
2018-06-13 08:04:09 -07:00
cases . add (
" use implicit casts to assign null to non-nullable pointer " ,
\\export fn entry() void {
\\ var x: i32 = 1234;
\\ var p: *i32 = &x;
\\ var pp: *?*i32 = &p;
\\ pp.* = null;
\\ var y = p.*;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:23: error: expected type '*?*i32', found '**i32' " ,
2018-06-13 08:04:09 -07:00
) ;
2018-06-05 20:54:14 -07:00
cases . add (
" attempted implicit cast from T to [*]const T " ,
\\export fn entry() void {
\\ const x: [*]const bool = true;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:30: error: expected type '[*]const bool', found 'bool' " ,
2018-06-05 20:54:14 -07:00
) ;
2018-06-05 19:23:23 -07:00
cases . add (
" dereference unknown length pointer " ,
\\export fn entry(x: [*]i32) i32 {
\\ return x.*;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32' " ,
2018-06-05 19:23:23 -07:00
) ;
2018-06-05 17:24:11 -07:00
cases . add (
" field access of unknown length pointer " ,
2018-11-13 05:08:37 -08:00
\\const Foo = extern struct {
2018-06-05 17:24:11 -07:00
\\ a: i32,
\\};
\\
\\export fn entry(foo: [*]Foo) void {
\\ foo.a += 1;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:8: error: type '[*]Foo' does not support field access " ,
2018-06-05 17:24:11 -07:00
) ;
2018-06-05 15:03:21 -07:00
cases . add (
" unknown length pointer to opaque " ,
\\export const T = [*]@OpaqueType();
,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:21: error: unknown-length pointer to opaque " ,
2018-06-05 15:03:21 -07:00
) ;
2018-06-05 07:48:53 -07:00
cases . add (
" error when evaluating return type " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2019-11-06 20:25:57 -08:00
\\ map: @as(i32, i32),
2018-06-05 07:48:53 -07:00
\\
\\ fn init() Foo {
\\ return undefined;
\\ }
\\};
\\export fn entry() void {
\\ var rule_set = try Foo.init();
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:10: error: expected type 'i32', found 'type' " ,
2018-06-05 07:48:53 -07:00
) ;
2018-06-04 19:11:14 -07:00
cases . add (
" slicing single-item pointer " ,
\\export fn entry(ptr: *i32) void {
\\ const slice = ptr[0..2];
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:22: error: slice of single-item pointer " ,
2018-06-04 19:11:14 -07:00
) ;
2018-06-03 22:09:15 -07:00
cases . add (
" indexing single-item pointer " ,
\\export fn entry(ptr: *i32) i32 {
\\ return ptr[1];
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: index of single-item pointer " ,
2018-06-03 22:09:15 -07:00
) ;
2018-06-02 12:20:51 -07:00
cases . add (
2018-06-19 15:51:46 -07:00
" nested error set mismatch " ,
2018-11-13 05:08:37 -08:00
\\const NextError = error{NextError};
\\const OtherError = error{OutOfMemory};
2018-06-02 12:20:51 -07:00
\\
\\export fn entry() void {
\\ const a: ?NextError!i32 = foo();
\\}
\\
\\fn foo() ?OtherError!i32 {
\\ return null;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32' " ,
" tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32' " ,
" tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError' " ,
" tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set " ,
2018-06-02 12:20:51 -07:00
) ;
2018-05-28 17:23:55 -07:00
cases . add (
" invalid deref on switch target " ,
2018-04-22 20:46:55 -07:00
\\comptime {
\\ var tile = Tile.Empty;
2018-05-17 20:21:44 -07:00
\\ switch (tile.*) {
2018-04-22 20:46:55 -07:00
\\ Tile.Empty => {},
\\ Tile.Filled => {},
\\ }
\\}
2018-11-13 05:08:37 -08:00
\\const Tile = enum {
2018-04-22 20:46:55 -07:00
\\ Empty,
\\ Filled,
\\};
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-04-22 20:46:55 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid field access in comptime " ,
2018-04-20 23:00:14 -07:00
\\comptime { var x = doesnt_exist.whatever; }
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-04-20 23:00:14 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" suspend inside suspend block " ,
2018-04-18 19:21:54 -07:00
\\export fn entry() void {
2019-08-11 16:53:10 -07:00
\\ _ = async foo();
2018-04-18 19:21:54 -07:00
\\}
\\async fn foo() void {
2018-07-29 01:18:54 -07:00
\\ suspend {
\\ suspend {
2018-04-18 19:21:54 -07:00
\\ }
\\ }
\\}
,
2019-08-11 16:53:10 -07:00
" tmp.zig:6:9: error: cannot suspend inside suspend block " ,
" tmp.zig:5:5: note: other suspend block here " ,
2018-05-28 17:23:55 -07:00
) ;
2018-04-18 19:21:54 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" assign inline fn to non-comptime var " ,
2018-04-12 13:26:23 -07:00
\\export fn entry() void {
\\ var a = b;
\\}
\\inline fn b() void { }
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var " ,
" tmp.zig:4:1: note: declared here " ,
2018-05-28 17:23:55 -07:00
) ;
2018-04-12 13:26:23 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" wrong type passed to @panic " ,
2018-03-27 12:07:45 -07:00
\\export fn entry() void {
\\ var e = error.Foo;
\\ @panic(e);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-03-27 12:07:45 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @tagName used on union with no associated enum tag " ,
2018-11-13 05:08:37 -08:00
\\const FloatInt = extern union {
2018-03-07 11:35:48 -08:00
\\ Float: f32,
\\ Int: i32,
\\};
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ var fi = FloatInt{.Float = 123.45};
2018-03-07 11:35:48 -08:00
\\ var tagName = @tagName(fi);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:7:19: error: union has no associated enum " ,
" tmp.zig:1:18: note: declared here " ,
2018-05-28 17:23:55 -07:00
) ;
2018-03-07 11:35:48 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" returning error from void async function " ,
2018-03-06 18:44:27 -08:00
\\export fn entry() void {
2019-08-11 16:53:10 -07:00
\\ _ = async amain();
2018-03-06 18:44:27 -08:00
\\}
\\async fn amain() void {
\\ return error.ShouldBeCompileError;
\\}
,
2019-08-11 16:53:10 -07:00
" tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-03-06 18:44:27 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
2019-11-23 23:14:21 -08:00
" var makes structs required to be comptime known " ,
2018-03-06 15:24:49 -08:00
\\export fn entry() void {
2019-11-23 23:14:21 -08:00
\\ const S = struct{v: var};
\\ var s = S{.v=@as(i32, 10)};
2018-03-06 15:24:49 -08:00
\\}
,
2019-11-23 23:14:21 -08:00
" tmp.zig:3:4: error: variable of type 'S' must be const or comptime " ,
2018-05-28 17:23:55 -07:00
) ;
2018-03-06 15:24:49 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @ptrCast discards const qualifier " ,
2018-03-06 13:37:03 -08:00
\\export fn entry() void {
\\ const x: i32 = 1234;
2018-05-31 07:56:59 -07:00
\\ const y = @ptrCast(*i32, &x);
2018-03-06 13:37:03 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:15: error: cast discards const qualifier " ,
2018-05-28 17:23:55 -07:00
) ;
2018-03-06 13:37:03 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" comptime slice of undefined pointer non-zero len " ,
2018-02-16 12:22:29 -08:00
\\export fn entry() void {
2019-11-08 12:56:21 -08:00
\\ const slice = @as([*]i32, undefined)[0..1];
2018-02-16 12:22:29 -08:00
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:41: error: non-zero length slice of undefined pointer " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-16 12:22:29 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" type checking function pointers " ,
2018-05-31 07:56:59 -07:00
\\fn a(b: fn (*const u8) void) void {
2018-02-14 13:24:43 -08:00
\\ b('a');
\\}
\\fn c(d: u8) void {
\\ @import("std").debug.warn("{c}\n", d);
\\}
\\export fn entry() void {
\\ a(c);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:8:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-14 13:24:43 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" no else prong on switch on global error set " ,
2018-02-09 10:49:58 -08:00
\\export fn entry() void {
\\ foo(error.A);
\\}
2018-11-13 05:08:37 -08:00
\\fn foo(a: anyerror) void {
2018-02-09 10:49:58 -08:00
\\ switch (a) {
\\ error.A => {},
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: else prong required when switching on type 'anyerror' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-09 10:49:58 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" inferred error set with no returned error " ,
2018-02-08 20:44:21 -08:00
\\export fn entry() void {
\\ foo() catch unreachable;
\\}
\\fn foo() !void {
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:11: error: function with inferred error set must return at least one possible error " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" error not handled in switch " ,
2018-02-08 20:44:21 -08:00
\\export fn entry() void {
\\ foo(452) catch |err| switch (err) {
\\ error.Foo => {},
\\ };
\\}
\\fn foo(x: i32) !void {
\\ switch (x) {
\\ 0 ... 10 => return error.Foo,
\\ 11 ... 20 => return error.Bar,
\\ 21 ... 30 => return error.Baz,
\\ else => {},
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:26: error: error.Baz not handled in switch " ,
" tmp.zig:2:26: error: error.Bar not handled in switch " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" duplicate error in switch " ,
2018-02-08 20:44:21 -08:00
\\export fn entry() void {
\\ foo(452) catch |err| switch (err) {
\\ error.Foo => {},
\\ error.Bar => {},
\\ error.Foo => {},
\\ else => {},
\\ };
\\}
\\fn foo(x: i32) !void {
\\ switch (x) {
\\ 0 ... 10 => return error.Foo,
\\ 11 ... 20 => return error.Bar,
\\ else => {},
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:14: error: duplicate switch value: '@typeOf(foo).ReturnType.ErrorSet.Foo' " ,
" tmp.zig:3:14: note: other value is here " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-07-06 13:20:46 -07:00
cases . add ( " invalid cast from integral type to enum " ,
2018-11-13 05:08:37 -08:00
\\const E = enum(usize) { One, Two };
2018-07-04 10:27:10 -07:00
\\
\\export fn entry() void {
\\ foo(1);
\\}
\\
\\fn foo(x: usize) void {
\\ switch (x) {
\\ E.One => {},
\\ }
\\}
2019-03-01 12:35:29 -08:00
, " tmp.zig:9:10: error: expected type 'usize', found 'E' " ) ;
2018-07-04 10:27:10 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" range operator in switch used on error set " ,
2018-02-08 20:44:21 -08:00
\\export fn entry() void {
\\ try foo(452) catch |err| switch (err) {
\\ error.A ... error.B => {},
\\ else => {},
\\ };
\\}
\\fn foo(x: i32) !void {
\\ switch (x) {
\\ 0 ... 10 => return error.Foo,
\\ 11 ... 20 => return error.Bar,
\\ else => {},
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:17: error: operator not allowed for errors " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" inferring error set of function pointer " ,
2018-02-08 20:44:21 -08:00
\\comptime {
\\ const z: ?fn()!void = null;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: inferring error set of return type valid only for function definitions " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" access non-existent member of error set " ,
2018-11-13 05:08:37 -08:00
\\const Foo = error{A};
2018-02-08 20:44:21 -08:00
\\comptime {
\\ const z = Foo.Bar;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:18: error: no error named 'Bar' in 'Foo' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" error union operator with non error set LHS " ,
2018-02-08 20:44:21 -08:00
\\comptime {
\\ const z = i32!i32;
2019-08-30 17:06:02 -07:00
\\ var x: z = undefined;
2018-02-08 20:44:21 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: expected error set type, found type 'i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" error equality but sets have no common members " ,
2018-11-13 05:08:37 -08:00
\\const Set1 = error{A, C};
\\const Set2 = error{B, D};
2018-02-08 20:44:21 -08:00
\\export fn entry() void {
\\ foo(Set1.A);
\\}
\\fn foo(x: Set1) void {
\\ if (x == Set2.B) {
\\
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" only equality binary operator allowed for error sets " ,
2018-02-08 20:44:21 -08:00
\\comptime {
\\ const z = error.A > error.B;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:23: error: operator not allowed for errors " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" explicit error set cast known at comptime violates error sets " ,
2018-11-13 05:08:37 -08:00
\\const Set1 = error {A, B};
\\const Set2 = error {A, C};
2018-02-08 20:44:21 -08:00
\\comptime {
\\ var x = Set1.B;
2018-06-18 14:25:29 -07:00
\\ var y = @errSetCast(Set2, x);
2018-02-08 20:44:21 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:13: error: error.B not a member of error set 'Set2' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" cast error union of global error set to error union of smaller error set " ,
2018-11-13 05:08:37 -08:00
\\const SmallErrorSet = error{A};
2018-02-08 20:44:21 -08:00
\\export fn entry() void {
\\ var x: SmallErrorSet!i32 = foo();
\\}
2018-11-13 05:08:37 -08:00
\\fn foo() anyerror!i32 {
2018-02-08 20:44:21 -08:00
\\ return error.B;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32' " ,
" tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet' " ,
" tmp.zig:3:35: note: cannot cast global error set into smaller set " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" cast global error set to error set " ,
2018-11-13 05:08:37 -08:00
\\const SmallErrorSet = error{A};
2018-02-08 20:44:21 -08:00
\\export fn entry() void {
\\ var x: SmallErrorSet = foo();
\\}
2018-11-13 05:08:37 -08:00
\\fn foo() anyerror {
2018-02-08 20:44:21 -08:00
\\ return error.B;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror' " ,
" tmp.zig:3:31: note: cannot cast global error set into smaller set " ,
2018-05-28 17:23:55 -07:00
) ;
cases . add (
" recursive inferred error set " ,
2018-02-08 20:44:21 -08:00
\\export fn entry() void {
\\ foo() catch unreachable;
\\}
\\fn foo() !void {
\\ try foo();
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: cannot resolve inferred error set '@typeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 20:44:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit cast of error set not a subset " ,
2018-11-13 05:08:37 -08:00
\\const Set1 = error{A, B};
\\const Set2 = error{A, C};
2018-02-08 18:54:44 -08:00
\\export fn entry() void {
\\ foo(Set1.B);
\\}
\\fn foo(set1: Set1) void {
\\ var x: Set2 = set1;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:7:19: error: expected type 'Set2', found 'Set1' " ,
" tmp.zig:1:23: note: 'error.B' not a member of destination error set " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 18:54:44 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" int to err global invalid number " ,
2018-11-13 05:08:37 -08:00
\\const Set1 = error{
2018-06-18 15:48:29 -07:00
\\ A,
\\ B,
\\};
2018-02-08 18:54:44 -08:00
\\comptime {
2018-06-18 15:48:29 -07:00
\\ var x: u16 = 3;
\\ var y = @intToError(x);
2018-02-08 18:54:44 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:7:13: error: integer value 3 represents no error " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 18:54:44 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" int to err non global invalid number " ,
2018-11-13 05:08:37 -08:00
\\const Set1 = error{
2018-06-18 15:48:29 -07:00
\\ A,
\\ B,
\\};
2018-11-13 05:08:37 -08:00
\\const Set2 = error{
2018-06-18 15:48:29 -07:00
\\ A,
\\ C,
\\};
2018-02-08 18:54:44 -08:00
\\comptime {
2018-06-18 15:48:29 -07:00
\\ var x = @errorToInt(Set1.B);
\\ var y = @errSetCast(Set2, @intToError(x));
2018-02-08 18:54:44 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:11:13: error: error.B not a member of error set 'Set2' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-08 18:54:44 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @memberCount of error " ,
2018-02-07 23:08:45 -08:00
\\comptime {
2018-11-13 05:08:37 -08:00
\\ _ = @memberCount(anyerror);
2018-02-07 23:08:45 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:9: error: global error set member count not available at comptime " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-07 23:08:45 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" duplicate error value in error set " ,
2018-11-13 05:08:37 -08:00
\\const Foo = error {
2018-02-07 23:08:45 -08:00
\\ Bar,
\\ Bar,
\\};
\\export fn entry() void {
\\ const a: Foo = undefined;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: duplicate error: 'Bar' " ,
" tmp.zig:2:5: note: other error here " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-07 23:08:45 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" cast negative integer literal to usize " ,
2018-02-05 06:26:39 -08:00
\\export fn entry() void {
2019-11-06 20:25:57 -08:00
\\ const x = @as(usize, -10);
2018-02-05 06:26:39 -08:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-05 06:26:39 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" use invalid number literal as array index " ,
2018-01-31 08:13:39 -08:00
\\var v = 25;
\\export fn entry() void {
\\ var arr: [v]u8 = undefined;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:1: error: unable to infer variable type " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-31 08:13:39 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" duplicate struct field " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2018-01-30 08:52:03 -08:00
\\ Bar: i32,
\\ Bar: usize,
\\};
\\export fn entry() void {
\\ const a: Foo = undefined;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: duplicate struct field: 'Bar' " ,
" tmp.zig:2:5: note: other field here " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-30 08:52:03 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" duplicate union field " ,
2018-11-13 05:08:37 -08:00
\\const Foo = union {
2018-01-30 08:52:03 -08:00
\\ Bar: i32,
\\ Bar: usize,
\\};
\\export fn entry() void {
\\ const a: Foo = undefined;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: duplicate union field: 'Bar' " ,
" tmp.zig:2:5: note: other field here " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-30 08:52:03 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" duplicate enum field " ,
2018-11-13 05:08:37 -08:00
\\const Foo = enum {
2018-01-30 08:52:03 -08:00
\\ Bar,
\\ Bar,
\\};
\\
\\export fn entry() void {
\\ const a: Foo = undefined;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: duplicate enum field: 'Bar' " ,
" tmp.zig:2:5: note: other field here " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-30 08:52:03 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" calling function with naked calling convention " ,
2018-01-29 11:01:12 -08:00
\\export fn entry() void {
\\ foo();
\\}
\\nakedcc fn foo() void { }
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: unable to call function with naked calling convention " ,
" tmp.zig:4:1: note: declared here " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-29 11:01:12 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" function with invalid return type " ,
2018-01-26 07:37:18 -08:00
\\export fn foo() boid {}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:17: error: use of undeclared identifier 'boid' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-26 07:37:18 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" function with non-extern non-packed enum parameter " ,
2018-11-13 05:08:37 -08:00
\\const Foo = enum { A, B, C };
2018-01-25 01:10:11 -08:00
\\export fn entry(foo: Foo) void { }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-22 19:24:07 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" function with non-extern non-packed struct parameter " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2018-01-22 19:24:07 -08:00
\\ A: i32,
\\ B: f32,
\\ C: bool,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry(foo: Foo) void { }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-22 19:24:07 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" function with non-extern non-packed union parameter " ,
2018-11-13 05:08:37 -08:00
\\const Foo = union {
2018-01-22 19:24:07 -08:00
\\ A: i32,
\\ B: f32,
\\ C: bool,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry(foo: Foo) void { }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-22 19:24:07 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" switch on enum with 1 field with no prongs " ,
2018-11-13 05:08:37 -08:00
\\const Foo = enum { M };
2018-01-21 11:44:24 -08:00
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-01-21 11:44:24 -08:00
\\ var f = Foo.M;
\\ switch (f) {}
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-21 11:44:24 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" shift by negative comptime integer " ,
2018-01-18 14:47:21 -08:00
\\comptime {
\\ var a = 1 >> -1;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:18: error: shift by negative value -1 " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-18 14:47:21 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @panic called at compile time " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-01-18 14:15:36 -08:00
\\ comptime {
2018-05-28 17:23:55 -07:00
\\ @panic("aoeu",);
2018-01-18 14:15:36 -08:00
\\ }
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: encountered @panic at compile-time " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-18 14:15:36 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" wrong return type for main " ,
2018-01-25 01:10:11 -08:00
\\pub fn main() f32 { }
2018-05-28 17:23:55 -07:00
,
2019-07-16 08:50:00 -07:00
" error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-14 21:01:02 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" double ?? on main return value " ,
2018-01-25 01:10:11 -08:00
\\pub fn main() ??void {
2018-01-14 21:01:02 -08:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-07-16 08:50:00 -07:00
" error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-14 21:01:02 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" bad identifier in function with struct defined inside function which references local const " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-01-06 21:20:26 -08:00
\\ const BlockKind = u32;
\\
2018-11-13 05:08:37 -08:00
\\ const Block = struct {
2018-01-06 21:20:26 -08:00
\\ kind: BlockKind,
\\ };
\\
\\ bogus;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:8:5: error: use of undeclared identifier 'bogus' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-01-06 21:20:26 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" labeled break not found " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-20 19:55:24 -08:00
\\ blah: while (true) {
\\ while (true) {
\\ break :outer;
\\ }
\\ }
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:13: error: label not found: 'outer' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-20 19:55:24 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" labeled continue not found " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-20 19:55:24 -08:00
\\ var i: usize = 0;
\\ blah: while (i < 10) : (i += 1) {
\\ while (true) {
\\ continue :outer;
\\ }
\\ }
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:13: error: labeled loop not found: 'outer' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-20 19:55:24 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" attempt to use 0 bit type in extern fn " ,
2018-05-31 07:56:59 -07:00
\\extern fn foo(ptr: extern fn(*void) void) void;
2017-12-19 15:21:42 -08:00
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-19 15:21:42 -08:00
\\ foo(bar);
\\}
\\
2018-05-31 07:56:59 -07:00
\\extern fn bar(x: *void) void { }
2019-06-25 15:06:03 -07:00
\\export fn entry2() void {
\\ bar(&{});
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc' " ,
" tmp.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-19 15:21:42 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - block statement " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ {}
\\ var good = {};
\\ ({})
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - block expr " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ _ = {};
\\ var good = {};
\\ _ = {}
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - comptime statement " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ comptime {}
\\ var good = {};
\\ comptime ({})
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - comptime expression " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ _ = comptime {};
\\ var good = {};
\\ _ = comptime {}
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - defer " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ defer {}
\\ var good = {};
\\ defer ({})
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - if statement " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ if(true) {}
\\ var good = {};
\\ if(true) ({})
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - if expression " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ _ = if(true) {};
\\ var good = {};
\\ _ = if(true) {}
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - if-else statement " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ if(true) {} else {}
\\ var good = {};
\\ if(true) ({}) else ({})
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - if-else expression " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ _ = if(true) {} else {};
\\ var good = {};
\\ _ = if(true) {} else {}
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - if-else-if statement " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ if(true) {} else if(true) {}
\\ var good = {};
\\ if(true) ({}) else if(true) ({})
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - if-else-if expression " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ _ = if(true) {} else if(true) {};
\\ var good = {};
\\ _ = if(true) {} else if(true) {}
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - if-else-if-else statement " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ if(true) {} else if(true) {} else {}
\\ var good = {};
\\ if(true) ({}) else if(true) ({}) else ({})
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - if-else-if-else expression " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ _ = if(true) {} else if(true) {} else {};
\\ var good = {};
\\ _ = if(true) {} else if(true) {} else {}
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - test statement " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-05-03 14:23:11 -07:00
\\ if (foo()) |_| {}
2017-04-19 01:12:22 -07:00
\\ var good = {};
2017-05-03 14:23:11 -07:00
\\ if (foo()) |_| ({})
2017-04-19 01:12:22 -07:00
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - test expression " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-05-03 14:23:11 -07:00
\\ _ = if (foo()) |_| {};
2017-04-19 01:12:22 -07:00
\\ var good = {};
2017-05-03 14:23:11 -07:00
\\ _ = if (foo()) |_| {}
2017-04-19 01:12:22 -07:00
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - while statement " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ while(true) {}
\\ var good = {};
\\ while(true) ({})
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - while expression " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ _ = while(true) {};
\\ var good = {};
\\ _ = while(true) {}
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - while-continue statement " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-05-03 15:12:07 -07:00
\\ while(true):({}) {}
2017-04-19 01:12:22 -07:00
\\ var good = {};
2017-05-03 15:12:07 -07:00
\\ while(true):({}) ({})
2017-04-19 01:12:22 -07:00
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - while-continue expression " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-05-03 15:12:07 -07:00
\\ _ = while(true):({}) {};
2017-04-19 01:12:22 -07:00
\\ var good = {};
2017-05-03 15:12:07 -07:00
\\ _ = while(true):({}) {}
2017-04-19 01:12:22 -07:00
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - for statement " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ for(foo()) |_| {}
2017-04-19 01:12:22 -07:00
\\ var good = {};
2018-11-13 05:08:37 -08:00
\\ for(foo()) |_| ({})
2017-04-19 01:12:22 -07:00
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicit semicolon - for expression " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ _ = for(foo()) |_| {};
2017-04-19 01:12:22 -07:00
\\ var good = {};
2018-11-13 05:08:37 -08:00
\\ _ = for(foo()) |_| {}
2017-04-19 01:12:22 -07:00
\\ var bad = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: expected token ';', found 'var' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" multiple function definitions " ,
2018-01-25 01:10:11 -08:00
\\fn a() void {}
\\fn a() void {}
\\export fn entry() void { a(); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:1: error: redefinition of 'a' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" unreachable with return " ,
2018-01-25 01:10:11 -08:00
\\fn a() noreturn {return;}
\\export fn entry() void { a(); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:18: error: expected type 'noreturn', found 'void' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" control reaches end of non-void function " ,
2018-01-25 01:10:11 -08:00
\\fn a() i32 {}
\\export fn entry() void { _ = a(); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:12: error: expected type 'i32', found 'void' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" undefined function call " ,
2018-01-25 01:10:11 -08:00
\\export fn a() void {
2017-04-19 01:12:22 -07:00
\\ b();
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: use of undeclared identifier 'b' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" wrong number of arguments " ,
2018-01-25 01:10:11 -08:00
\\export fn a() void {
2017-04-19 01:12:22 -07:00
\\ b(1);
\\}
2018-01-25 01:10:11 -08:00
\\fn b(a: i32, b: i32, c: i32) void { }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:6: error: expected 3 arguments, found 1 " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid type " ,
2018-01-25 01:10:11 -08:00
\\fn a() bogus {}
\\export fn entry() void { _ = a(); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:8: error: use of undeclared identifier 'bogus' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" pointer to noreturn " ,
2018-05-31 07:56:59 -07:00
\\fn a() *noreturn {}
2018-01-25 01:10:11 -08:00
\\export fn entry() void { _ = a(); }
2018-05-28 17:23:55 -07:00
,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:9: error: pointer to noreturn not allowed " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" unreachable code " ,
2018-01-25 01:10:11 -08:00
\\export fn a() void {
2017-04-19 01:12:22 -07:00
\\ return;
\\ b();
\\}
\\
2018-01-25 01:10:11 -08:00
\\fn b() void {}
2018-05-28 17:23:55 -07:00
,
2019-06-25 15:06:03 -07:00
" tmp.zig:3:6: error: unreachable code " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" bad import " ,
\\const bogus = @import("bogus-does-not-exist.zig",);
2018-01-25 01:10:11 -08:00
\\export fn entry() void { bogus.bogo(); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:15: error: unable to find 'bogus-does-not-exist.zig' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" undeclared identifier " ,
2018-01-25 01:10:11 -08:00
\\export fn a() void {
2017-12-21 21:50:30 -08:00
\\ return
2017-04-19 01:12:22 -07:00
\\ b +
2017-12-21 21:50:30 -08:00
\\ c;
2017-04-19 01:12:22 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undeclared identifier 'b' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" parameter redeclaration " ,
2018-01-25 01:10:11 -08:00
\\fn f(a : i32, a : i32) void {
2017-04-19 01:12:22 -07:00
\\}
2018-01-25 01:10:11 -08:00
\\export fn entry() void { f(1, 2); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:15: error: redeclaration of variable 'a' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" local variable redeclaration " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ const a : i32 = 0;
\\ const a = 0;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: redeclaration of variable 'a' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" local variable redeclares parameter " ,
2018-01-25 01:10:11 -08:00
\\fn f(a : i32) void {
2017-04-19 01:12:22 -07:00
\\ const a = 0;
\\}
2018-01-25 01:10:11 -08:00
\\export fn entry() void { f(1); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: redeclaration of variable 'a' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" variable has wrong type " ,
2018-01-25 01:10:11 -08:00
\\export fn f() i32 {
2019-11-19 17:29:08 -08:00
\\ const a = "a";
2017-12-21 21:50:30 -08:00
\\ return a;
2017-04-19 01:12:22 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-11-23 23:14:21 -08:00
" tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" if condition is bool, not int " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ if (0) {}
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:9: error: expected type 'bool', found 'comptime_int' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" assign unreachable " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ const a = return;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: unreachable code " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" unreachable variable " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ const a: noreturn = {};
\\}
2018-05-28 17:23:55 -07:00
,
2019-06-25 15:06:03 -07:00
" tmp.zig:2:25: error: expected type 'noreturn', found 'void' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" unreachable parameter " ,
2018-01-25 01:10:11 -08:00
\\fn f(a: noreturn) void {}
\\export fn entry() void { f(); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:9: error: parameter of type 'noreturn' not allowed " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" bad assignment target " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ 3 = 3;
\\}
2018-05-28 17:23:55 -07:00
,
2019-08-02 13:09:40 -07:00
" tmp.zig:2:9: error: cannot assign to constant " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" assign to constant variable " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ const a = 3;
\\ a = 4;
\\}
2018-05-28 17:23:55 -07:00
,
2019-08-02 13:09:40 -07:00
" tmp.zig:3:9: error: cannot assign to constant " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" use of undeclared identifier " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ b = 3;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: use of undeclared identifier 'b' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" const is a statement, not an expression " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ (const a = 0);
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:6: error: invalid token: 'const' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" array access of undeclared identifier " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ i[i] = i[i];
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: use of undeclared identifier 'i' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" array access of non array " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ var bad : bool = undefined;
\\ bad[bad] = bad[bad];
\\}
2019-06-25 15:06:03 -07:00
\\export fn g() void {
\\ var bad : bool = undefined;
\\ _ = bad[bad];
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:8: error: array access of non-array type 'bool' " ,
2019-06-25 15:06:03 -07:00
" tmp.zig:7:12: error: array access of non-array type 'bool' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" array access with non integer index " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ var array = "aoeu";
\\ var bad = false;
\\ array[bad] = array[bad];
\\}
2019-06-25 15:06:03 -07:00
\\export fn g() void {
\\ var array = "aoeu";
\\ var bad = false;
\\ _ = array[bad];
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:11: error: expected type 'usize', found 'bool' " ,
2019-06-25 15:06:03 -07:00
" tmp.zig:9:15: error: expected type 'usize', found 'bool' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" write to const global variable " ,
2017-04-19 01:12:22 -07:00
\\const x : i32 = 99;
2018-01-25 01:10:11 -08:00
\\fn f() void {
2017-04-19 01:12:22 -07:00
\\ x = 1;
\\}
2018-01-25 01:10:11 -08:00
\\export fn entry() void { f(); }
2018-05-28 17:23:55 -07:00
,
2019-08-02 13:09:40 -07:00
" tmp.zig:3:9: error: cannot assign to constant " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" missing else clause " ,
2018-01-25 01:10:11 -08:00
\\fn f(b: bool) void {
2017-12-21 21:50:30 -08:00
\\ const x : i32 = if (b) h: { break :h 1; };
2019-06-25 15:06:03 -07:00
\\}
\\fn g(b: bool) void {
2019-11-06 20:25:57 -08:00
\\ const y = if (b) h: { break :h @as(i32, 1); };
2017-04-19 01:12:22 -07:00
\\}
2019-06-25 15:06:03 -07:00
\\export fn entry() void { f(true); g(true); }
2018-05-28 17:23:55 -07:00
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:21: error: expected type 'i32', found 'void' " ,
2019-06-25 15:06:03 -07:00
" tmp.zig:5:15: error: incompatible types: 'i32' and 'void' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid struct field " ,
2018-11-13 05:08:37 -08:00
\\const A = struct { x : i32, };
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ var a : A = undefined;
\\ a.foo = 1;
\\ const y = a.bar;
\\}
2019-06-25 15:06:03 -07:00
\\export fn g() void {
\\ var a : A = undefined;
\\ const y = a.bar;
\\}
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:6: error: no member named 'foo' in struct 'A' " ,
2019-06-25 15:06:03 -07:00
" tmp.zig:9:16: error: no member named 'bar' in struct 'A' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" redefinition of struct " ,
2018-11-13 05:08:37 -08:00
\\const A = struct { x : i32, };
\\const A = struct { y : i32, };
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:1: error: redefinition of 'A' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" redefinition of enums " ,
2018-11-13 05:08:37 -08:00
\\const A = enum {};
\\const A = enum {};
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:1: error: redefinition of 'A' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" redefinition of global variables " ,
2017-04-19 01:12:22 -07:00
\\var a : i32 = 1;
\\var a : i32 = 2;
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:1: error: redefinition of 'a' " ,
" tmp.zig:1:1: note: previous definition is here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" duplicate field in struct value expression " ,
2018-11-13 05:08:37 -08:00
\\const A = struct {
2017-04-19 01:12:22 -07:00
\\ x : i32,
\\ y : i32,
\\ z : i32,
\\};
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2018-11-13 05:08:37 -08:00
\\ const a = A {
2017-04-19 01:12:22 -07:00
\\ .z = 1,
\\ .y = 2,
\\ .x = 3,
\\ .z = 4,
\\ };
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:11:9: error: duplicate field " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" missing field in struct value expression " ,
2018-11-13 05:08:37 -08:00
\\const A = struct {
2017-04-19 01:12:22 -07:00
\\ x : i32,
\\ y : i32,
\\ z : i32,
\\};
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ // we want the error on the '{' not the 'A' because
\\ // the A could be a complicated expression
2018-11-13 05:08:37 -08:00
\\ const a = A {
2017-04-19 01:12:22 -07:00
\\ .z = 4,
\\ .y = 2,
\\ };
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:9:17: error: missing field: 'x' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid field in struct value expression " ,
2018-11-13 05:08:37 -08:00
\\const A = struct {
2017-04-19 01:12:22 -07:00
\\ x : i32,
\\ y : i32,
\\ z : i32,
\\};
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2018-11-13 05:08:37 -08:00
\\ const a = A {
2017-04-19 01:12:22 -07:00
\\ .z = 4,
\\ .y = 2,
\\ .foo = 42,
\\ };
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:10:9: error: no member named 'foo' in struct 'A' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid break expression " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ break;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: break expression outside loop " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid continue expression " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ continue;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: continue expression outside loop " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid maybe type " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-05-03 14:23:11 -07:00
\\ if (true) |x| { }
2017-04-19 01:12:22 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:9: error: expected optional type, found 'bool' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" cast unreachable " ,
2018-01-25 01:10:11 -08:00
\\fn f() i32 {
2019-11-06 20:25:57 -08:00
\\ return @as(i32, return 1);
2017-04-19 01:12:22 -07:00
\\}
2018-01-25 01:10:11 -08:00
\\export fn entry() void { _ = f(); }
2018-05-28 17:23:55 -07:00
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:12: error: unreachable code " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid builtin fn " ,
2018-01-25 01:10:11 -08:00
\\fn f() @bogus(foo) {
2017-04-19 01:12:22 -07:00
\\}
2018-01-25 01:10:11 -08:00
\\export fn entry() void { _ = f(); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:8: error: invalid builtin function: 'bogus' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" noalias on non pointer param " ,
2018-01-25 01:10:11 -08:00
\\fn f(noalias x: i32) void {}
\\export fn entry() void { f(1234); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:6: error: noalias on non-pointer parameter " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" struct init syntax for array " ,
2019-06-09 16:24:24 -07:00
\\const foo = [3]u16{ .x = 1024 };
\\comptime {
\\ _ = foo;
\\}
2018-05-28 17:23:55 -07:00
,
2019-06-25 15:06:03 -07:00
" tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" type variables must be constant " ,
2017-04-19 01:12:22 -07:00
\\var foo = u8;
2018-01-25 01:10:11 -08:00
\\export fn entry() foo {
2017-04-19 01:12:22 -07:00
\\ return 1;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:1: error: variable of type 'type' must be constant " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" variables shadowing types " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {};
\\const Bar = struct {};
2017-04-19 01:12:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\fn f(Foo: i32) void {
2017-04-19 01:12:22 -07:00
\\ var Bar : i32 = undefined;
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ f(1234);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:6: error: redefinition of 'Foo' " ,
" tmp.zig:1:1: note: previous definition is here " ,
" tmp.zig:5:5: error: redefinition of 'Bar' " ,
" tmp.zig:2:1: note: previous definition is here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" switch expression - missing enumeration prong " ,
2018-11-13 05:08:37 -08:00
\\const Number = enum {
2017-05-07 09:07:35 -07:00
\\ One,
\\ Two,
\\ Three,
\\ Four,
\\};
2018-01-25 01:10:11 -08:00
\\fn f(n: Number) i32 {
2017-05-07 09:07:35 -07:00
\\ switch (n) {
\\ Number.One => 1,
\\ Number.Two => 2,
2019-11-06 20:25:57 -08:00
\\ Number.Three => @as(i32, 3),
2017-05-07 09:07:35 -07:00
\\ }
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(f)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-07 09:07:35 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" switch expression - duplicate enumeration prong " ,
2018-11-13 05:08:37 -08:00
\\const Number = enum {
2017-05-07 09:07:35 -07:00
\\ One,
\\ Two,
\\ Three,
\\ Four,
\\};
2018-01-25 01:10:11 -08:00
\\fn f(n: Number) i32 {
2017-05-07 09:07:35 -07:00
\\ switch (n) {
\\ Number.One => 1,
\\ Number.Two => 2,
2019-11-06 20:25:57 -08:00
\\ Number.Three => @as(i32, 3),
2017-05-07 09:07:35 -07:00
\\ Number.Four => 4,
\\ Number.Two => 2,
\\ }
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(f)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:13:15: error: duplicate switch value " ,
" tmp.zig:10:15: note: other value is here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-07 10:40:35 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" switch expression - duplicate enumeration prong when else present " ,
2018-11-13 05:08:37 -08:00
\\const Number = enum {
2017-05-07 10:40:35 -07:00
\\ One,
\\ Two,
\\ Three,
\\ Four,
\\};
2018-01-25 01:10:11 -08:00
\\fn f(n: Number) i32 {
2017-05-07 10:40:35 -07:00
\\ switch (n) {
\\ Number.One => 1,
\\ Number.Two => 2,
2019-11-06 20:25:57 -08:00
\\ Number.Three => @as(i32, 3),
2017-05-07 10:40:35 -07:00
\\ Number.Four => 4,
\\ Number.Two => 2,
\\ else => 10,
\\ }
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(f)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:13:15: error: duplicate switch value " ,
" tmp.zig:10:15: note: other value is here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-07 09:07:35 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" switch expression - multiple else prongs " ,
2018-01-25 01:10:11 -08:00
\\fn f(x: u32) void {
2017-04-19 01:12:22 -07:00
\\ const value: bool = switch (x) {
\\ 1234 => false,
\\ else => true,
\\ else => true,
\\ };
\\}
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ f(1234);
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:9: error: multiple else prongs in switch expression " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" switch expression - non exhaustive integer prongs " ,
2018-01-25 01:10:11 -08:00
\\fn foo(x: u8) void {
2017-05-07 09:07:35 -07:00
\\ switch (x) {
\\ 0 => {},
\\ }
\\}
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2017-05-07 09:07:35 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: switch must handle all possibilities " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-07 09:07:35 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" switch expression - duplicate or overlapping integer value " ,
2018-01-25 01:10:11 -08:00
\\fn foo(x: u8) u8 {
2017-12-21 21:50:30 -08:00
\\ return switch (x) {
2019-11-06 20:25:57 -08:00
\\ 0 ... 100 => @as(u8, 0),
2017-05-07 09:07:35 -07:00
\\ 101 ... 200 => 1,
\\ 201, 203 ... 207 => 2,
\\ 206 ... 255 => 3,
2017-12-21 21:50:30 -08:00
\\ };
2017-05-07 09:07:35 -07:00
\\}
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2017-05-07 09:07:35 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:9: error: duplicate switch value " ,
" tmp.zig:5:14: note: previous value is here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-07 09:07:35 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" switch expression - switch on pointer type with no else " ,
2018-05-31 07:56:59 -07:00
\\fn foo(x: *u8) void {
2017-05-07 09:07:35 -07:00
\\ switch (x) {
\\ &y => {},
\\ }
\\}
\\const y: u8 = 100;
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2017-05-07 09:07:35 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: else prong required when switching on type '*u8' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-07 09:07:35 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" global variable initializer must be constant expression " ,
2018-01-25 01:10:11 -08:00
\\extern fn foo() i32;
2017-04-19 01:12:22 -07:00
\\const x = foo();
2018-01-25 01:10:11 -08:00
\\export fn entry() i32 { return x; }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:11: error: unable to evaluate constant expression " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" array concatenation with wrong type " ,
2017-04-19 01:12:22 -07:00
\\const src = "aoeu";
2019-11-20 13:08:01 -08:00
\\const derp: usize = 1234;
2017-04-19 01:12:22 -07:00
\\const a = derp ++ "foo";
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(a)); }
2018-05-28 17:23:55 -07:00
,
2019-11-20 13:08:01 -08:00
" tmp.zig:3:11: error: expected array, found 'usize' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" non compile time array concatenation " ,
2018-01-25 01:10:11 -08:00
\\fn f() []u8 {
2017-12-21 21:50:30 -08:00
\\ return s ++ "foo";
2017-04-19 01:12:22 -07:00
\\}
\\var s: [10]u8 = undefined;
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(f)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:12: error: unable to evaluate constant expression " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @cImport with bogus include " ,
2017-04-19 01:12:22 -07:00
\\const c = @cImport(@cInclude("bogus.h"));
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:11: error: C import failed " ,
2018-05-28 17:23:55 -07:00
" .h:1:10: note: 'bogus.h' file not found " ,
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" address of number literal " ,
2017-04-19 01:12:22 -07:00
\\const x = 3;
\\const y = &x;
2018-05-31 07:56:59 -07:00
\\fn foo() *const i32 { return y; }
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" integer overflow error " ,
2017-04-19 01:12:22 -07:00
\\const x : u8 = 300;
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(x)); }
2018-05-28 17:23:55 -07:00
,
2019-11-08 12:56:21 -08:00
" tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-06-29 11:52:25 -07:00
cases . add (
" invalid shift amount error " ,
\\const x : u8 = 2;
\\fn f() u16 {
\\ return x << 8;
\\}
\\export fn entry() u16 { return f(); }
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:14: error: RHS of shift is too large for LHS type " ,
" tmp.zig:3:17: note: value 8 cannot fit into type u3 " ,
2018-06-29 11:52:25 -07:00
) ;
2018-05-28 17:23:55 -07:00
cases . add (
" missing function call param " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2017-04-19 01:12:22 -07:00
\\ a: i32,
\\ b: i32,
\\
2018-05-31 07:56:59 -07:00
\\ fn member_a(foo: *const Foo) i32 {
2017-04-19 01:12:22 -07:00
\\ return foo.a;
\\ }
2018-05-31 07:56:59 -07:00
\\ fn member_b(foo: *const Foo) i32 {
2017-04-19 01:12:22 -07:00
\\ return foo.b;
\\ }
\\};
\\
\\const member_fn_type = @typeOf(Foo.member_a);
2019-06-09 16:24:24 -07:00
\\const members = [_]member_fn_type {
2017-04-19 01:12:22 -07:00
\\ Foo.member_a,
\\ Foo.member_b,
\\};
\\
2018-05-31 07:56:59 -07:00
\\fn f(foo: *const Foo, index: usize) void {
2017-04-19 01:12:22 -07:00
\\ const result = members[index]();
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(f)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:20:34: error: expected 1 arguments, found 0 " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
`@import("std").builtin`. The target-related types are moved
to `std.Target`. This allows the data types to have methods, such as
`std.Target.current.isDarwin()`.
* `std.os.windows.subsystem` is moved to
`std.Target.current.subsystem`.
* Remove the concept of the panic package from the compiler
implementation. Instead, `std.builtin.panic` is always the panic
function. It checks for `@hasDecl(@import("root"), "panic")`,
or else provides a default implementation.
This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 15:43:24 -07:00
" missing function name " ,
2018-01-25 01:10:11 -08:00
\\fn () void {}
\\export fn entry() usize { return @sizeOf(@typeOf(f)); }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:1: error: missing function name " ,
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
`@import("std").builtin`. The target-related types are moved
to `std.Target`. This allows the data types to have methods, such as
`std.Target.current.isDarwin()`.
* `std.os.windows.subsystem` is moved to
`std.Target.current.subsystem`.
* Remove the concept of the panic package from the compiler
implementation. Instead, `std.builtin.panic` is always the panic
function. It checks for `@hasDecl(@import("root"), "panic")`,
or else provides a default implementation.
This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 15:43:24 -07:00
) ;
cases . add (
" missing param name " ,
\\fn f(i32) void {}
\\export fn entry() usize { return @sizeOf(@typeOf(f)); }
,
" tmp.zig:1:6: error: missing parameter name " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" wrong function type " ,
2019-06-09 16:24:24 -07:00
\\const fns = [_]fn() void { a, b, c };
2018-01-25 01:10:11 -08:00
\\fn a() i32 {return 0;}
\\fn b() i32 {return 1;}
\\fn c() i32 {return 2;}
\\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
2018-05-28 17:23:55 -07:00
,
2019-06-09 16:24:24 -07:00
" tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" extern function pointer mismatch " ,
2019-06-09 16:24:24 -07:00
\\const fns = [_](fn(i32)i32) { a, b, c };
2018-01-25 01:10:11 -08:00
\\pub fn a(x: i32) i32 {return x + 0;}
\\pub fn b(x: i32) i32 {return x + 1;}
\\export fn c(x: i32) i32 {return x + 2;}
2017-04-19 01:12:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
2018-05-28 17:23:55 -07:00
,
2019-06-09 16:24:24 -07:00
" tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" colliding invalid top level functions " ,
2018-01-25 01:10:11 -08:00
\\fn func() bogus {}
\\fn func() bogus {}
\\export fn entry() usize { return @sizeOf(@typeOf(func)); }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:1: error: redefinition of 'func' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
2019-08-26 19:38:45 -07:00
" non constant expression in array size " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2017-04-19 01:12:22 -07:00
\\ y: [get()]u8,
\\};
\\var global_var: usize = 1;
2018-01-25 01:10:11 -08:00
\\fn get() usize { return global_var; }
2017-04-19 01:12:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(Foo)); }
2017-04-19 01:12:22 -07:00
,
2019-08-15 11:05:12 -07:00
" tmp.zig:5:25: error: unable to evaluate constant expression " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:2:12: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" addition with non numbers " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2017-04-19 01:12:22 -07:00
\\ field: i32,
\\};
2018-11-13 05:08:37 -08:00
\\const x = Foo {.field = 1} + Foo {.field = 2};
2017-04-19 01:12:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(x)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" division by zero " ,
2017-04-19 01:12:22 -07:00
\\const lit_int_x = 1 / 0;
\\const lit_float_x = 1.0 / 0.0;
2019-11-06 20:25:57 -08:00
\\const int_x = @as(u32, 1) / @as(u32, 0);
2019-11-07 15:52:09 -08:00
\\const float_x = @as(f32, 1.0) / @as(f32, 0.0);
2017-04-19 01:12:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); }
\\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); }
\\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); }
\\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:21: error: division by zero " ,
" tmp.zig:2:25: error: division by zero " ,
2019-11-08 12:56:21 -08:00
" tmp.zig:3:27: error: division by zero " ,
" tmp.zig:4:31: error: division by zero " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" normal string with newline " ,
2017-04-19 01:12:22 -07:00
\\const foo = "a
\\b";
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:15: error: newline not allowed in string literal " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid comparison for function pointers " ,
2018-01-25 01:10:11 -08:00
\\fn foo() void {}
2017-04-19 01:12:22 -07:00
\\const invalid = foo > foo;
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(invalid)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:21: error: operator not allowed for type 'fn() void' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" generic function instance with non-constant expression " ,
2018-01-25 01:10:11 -08:00
\\fn foo(comptime x: i32, y: i32) i32 { return x + y; }
\\fn test1(a: i32, b: i32) i32 {
2017-04-19 01:12:22 -07:00
\\ return foo(a, b);
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(test1)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:16: error: unable to evaluate constant expression " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
2018-06-09 20:42:14 -07:00
" assign null to non-optional pointer " ,
2018-05-31 07:56:59 -07:00
\\const a: *u8 = null;
2017-04-19 01:12:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(a)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:16: error: expected type '*u8', found '(null)' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" indexing an array of size zero " ,
2019-06-09 16:24:24 -07:00
\\const array = [_]u8{};
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-19 01:12:22 -07:00
\\ const pointer = &array[0];
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:27: error: index 0 outside array of size 0 " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" compile time division by zero " ,
2017-04-19 01:12:22 -07:00
\\const y = foo(0);
2018-01-25 01:10:11 -08:00
\\fn foo(x: u32) u32 {
2017-12-21 21:50:30 -08:00
\\ return 1 / x;
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(y)); }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:14: error: division by zero " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:14: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" branch on undefined value " ,
2017-04-19 01:12:22 -07:00
\\const x = if (undefined) true else false;
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(x)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:15: error: use of undefined value here causes undefined behavior " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-06-30 11:50:09 -07:00
cases . add (
" div on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a / a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" div assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a /= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" mod on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a % a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" mod assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a %= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" add on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a + a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" add assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a += a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" add wrap on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a +% a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" add wrap assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a +%= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" sub on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a - a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" sub assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a -= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" sub wrap on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a -% a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" sub wrap assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a -%= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" mult on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a * a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" mult assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a *= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" mult wrap on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a *% a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" mult wrap assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a *%= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" shift left on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a << 2;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" shift left assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a <<= 2;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" shift right on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a >> 2;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" shift left assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a >>= 2;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" bin and on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a & a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" bin and assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a &= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" bin or on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a | a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" bin or assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a |= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" bin xor on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a ^ a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" bin xor assign on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ a ^= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" equal on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a == a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" not equal on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a != a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" greater than on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a > a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" greater than equal on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a >= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" less than on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a < a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" less than equal on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = a <= a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" and on undefined value " ,
\\comptime {
\\ var a: bool = undefined;
\\ _ = a and a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" or on undefined value " ,
\\comptime {
\\ var a: bool = undefined;
\\ _ = a or a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" negate on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = -a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:10: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" negate wrap on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = -%a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:11: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" bin not on undefined value " ,
\\comptime {
\\ var a: i64 = undefined;
\\ _ = ~a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:10: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" bool not on undefined value " ,
\\comptime {
\\ var a: bool = undefined;
\\ _ = !a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:10: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" orelse on undefined value " ,
\\comptime {
\\ var a: ?bool = undefined;
\\ _ = a orelse false;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:11: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" catch on undefined value " ,
\\comptime {
2018-11-13 05:08:37 -08:00
\\ var a: anyerror!bool = undefined;
2018-06-30 11:50:09 -07:00
\\ _ = a catch |err| false;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:11: error: use of undefined value here causes undefined behavior " ,
2018-06-30 11:50:09 -07:00
) ;
cases . add (
" deref on undefined value " ,
\\comptime {
\\ var a: *u8 = undefined;
\\ _ = a.*;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:9: error: attempt to dereference undefined value " ,
2018-06-30 11:50:09 -07:00
) ;
2018-05-28 17:23:55 -07:00
cases . add (
" endless loop in function evaluation " ,
2017-04-19 01:12:22 -07:00
\\const seventh_fib_number = fibbonaci(7);
2018-01-25 01:10:11 -08:00
\\fn fibbonaci(x: i32) i32 {
2017-04-19 01:12:22 -07:00
\\ return fibbonaci(x - 1) + fibbonaci(x - 2);
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:37: note: referenced here " ,
" tmp.zig:6:50: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @embedFile with bogus file " ,
\\const resource = @embedFile("bogus.txt",);
2017-04-19 01:12:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(resource)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:29: error: unable to find ' " ,
2018-05-28 17:23:55 -07:00
" bogus.txt' " ,
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" non-const expression in struct literal outside function " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2017-04-19 01:12:22 -07:00
\\ x: i32,
\\};
2018-11-13 05:08:37 -08:00
\\const a = Foo {.x = get_it()};
2018-01-25 01:10:11 -08:00
\\extern fn get_it() i32;
2017-04-19 01:12:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(a)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:21: error: unable to evaluate constant expression " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" non-const expression function call with struct return value outside function " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2017-04-19 01:12:22 -07:00
\\ x: i32,
\\};
\\const a = get_it();
2018-01-25 01:10:11 -08:00
\\fn get_it() Foo {
2017-04-19 01:12:22 -07:00
\\ global_side_effect = true;
2018-11-13 05:08:37 -08:00
\\ return Foo {.x = 13};
2017-04-19 01:12:22 -07:00
\\}
\\var global_side_effect = false;
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(a)); }
2017-04-19 01:12:22 -07:00
,
2019-08-02 13:09:40 -07:00
" tmp.zig:6:26: error: unable to evaluate constant expression " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:4:17: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" undeclared identifier error should mark fn as impure " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-19 01:12:22 -07:00
\\ test_a_thing();
\\}
2018-01-25 01:10:11 -08:00
\\fn test_a_thing() void {
2017-04-19 01:12:22 -07:00
\\ bad_fn_call();
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" illegal comparison of types " ,
2018-01-25 01:10:11 -08:00
\\fn bad_eql_1(a: []u8, b: []u8) bool {
2017-12-21 21:50:30 -08:00
\\ return a == b;
2017-04-19 01:12:22 -07:00
\\}
2018-11-13 05:08:37 -08:00
\\const EnumWithData = union(enum) {
2017-12-03 17:43:56 -08:00
\\ One: void,
2017-04-19 01:12:22 -07:00
\\ Two: i32,
\\};
2018-05-31 07:56:59 -07:00
\\fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
2018-05-17 20:21:44 -07:00
\\ return a.* == b.*;
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); }
\\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:14: error: operator not allowed for type '[]u8' " ,
" tmp.zig:9:16: error: operator not allowed for type 'EnumWithData' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" non-const switch number literal " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-19 01:12:22 -07:00
\\ const x = switch (bar()) {
\\ 1, 2 => 1,
\\ 3, 4 => 2,
\\ else => 3,
\\ };
\\}
2018-01-25 01:10:11 -08:00
\\fn bar() i32 {
2017-12-21 21:50:30 -08:00
\\ return 2;
2017-04-19 01:12:22 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-06-25 16:03:56 -07:00
" tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" atomic orderings of cmpxchg - failure stricter than success " ,
2017-05-01 10:12:38 -07:00
\\const AtomicOrder = @import("builtin").AtomicOrder;
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ var x: i32 = 1234;
2018-04-18 09:16:42 -07:00
\\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
2017-04-19 01:12:22 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:81: error: failure atomic ordering must be no stricter than success " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" atomic orderings of cmpxchg - success Monotonic or stricter " ,
2017-05-01 10:12:38 -07:00
\\const AtomicOrder = @import("builtin").AtomicOrder;
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ var x: i32 = 1234;
2018-04-18 09:16:42 -07:00
\\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
2017-04-19 01:12:22 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" negation overflow in function evaluation " ,
2017-04-19 01:12:22 -07:00
\\const y = neg(-128);
2018-01-25 01:10:11 -08:00
\\fn neg(x: i8) i8 {
2017-12-21 21:50:30 -08:00
\\ return -x;
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(y)); }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:12: error: negation caused overflow " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:14: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" add overflow in function evaluation " ,
2017-04-19 01:12:22 -07:00
\\const y = add(65530, 10);
2018-01-25 01:10:11 -08:00
\\fn add(a: u16, b: u16) u16 {
2017-12-21 21:50:30 -08:00
\\ return a + b;
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(y)); }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:14: error: operation caused overflow " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:14: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" sub overflow in function evaluation " ,
2017-04-19 01:12:22 -07:00
\\const y = sub(10, 20);
2018-01-25 01:10:11 -08:00
\\fn sub(a: u16, b: u16) u16 {
2017-12-21 21:50:30 -08:00
\\ return a - b;
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(y)); }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:14: error: operation caused overflow " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:14: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" mul overflow in function evaluation " ,
2017-04-19 01:12:22 -07:00
\\const y = mul(300, 6000);
2018-01-25 01:10:11 -08:00
\\fn mul(a: u16, b: u16) u16 {
2017-12-21 21:50:30 -08:00
\\ return a * b;
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(y)); }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:14: error: operation caused overflow " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:14: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" truncate sign mismatch " ,
2018-01-25 01:10:11 -08:00
\\fn f() i8 {
2019-02-09 18:10:59 -08:00
\\ var x: u32 = 10;
2017-12-21 21:50:30 -08:00
\\ return @truncate(i8, x);
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(f)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:26: error: expected signed integer type, found 'u32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" try in function with non error return type " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2018-01-07 13:51:46 -08:00
\\ try something();
2017-04-19 01:12:22 -07:00
\\}
2018-11-13 05:08:37 -08:00
\\fn something() anyerror!void { }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: expected type 'void', found 'anyerror' " ,
" tmp.zig:1:15: note: return type declared here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid pointer for var type " ,
2018-01-25 01:10:11 -08:00
\\extern fn ext() usize;
2017-04-19 01:12:22 -07:00
\\var bytes: [ext()]u8 = undefined;
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ for (bytes) |*b, i| {
2019-11-06 20:25:57 -08:00
\\ b.* = @as(u8, i);
2017-04-19 01:12:22 -07:00
\\ }
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:13: error: unable to evaluate constant expression " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" export function with comptime parameter " ,
2018-01-25 01:10:11 -08:00
\\export fn foo(comptime x: i32, y: i32) i32{
2017-12-21 21:50:30 -08:00
\\ return x + y;
2017-04-19 01:12:22 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" extern function with comptime parameter " ,
2018-01-25 01:10:11 -08:00
\\extern fn foo(comptime x: i32, y: i32) i32;
\\fn f() i32 {
2017-12-21 21:50:30 -08:00
\\ return foo(1, 2);
2017-04-19 01:12:22 -07:00
\\}
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(f)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" convert fixed size array to slice with invalid size " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ var array: [5]u8 = undefined;
2018-06-18 14:25:29 -07:00
\\ var foo = @bytesToSlice(u32, array)[0];
2017-04-19 01:12:22 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:15: error: unable to convert [5]u8 to []align(1) const u32: size mismatch " ,
" tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1 " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" non-pure function returns type " ,
2017-04-19 01:12:22 -07:00
\\var a: u32 = 0;
2018-01-25 01:10:11 -08:00
\\pub fn List(comptime T: type) type {
2017-04-19 01:12:22 -07:00
\\ a += 1;
2017-12-21 21:50:30 -08:00
\\ return SmallList(T, 8);
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
2018-11-13 05:08:37 -08:00
\\ return struct {
2017-04-19 01:12:22 -07:00
\\ items: []T,
\\ length: usize,
\\ prealloc_items: [STATIC_SIZE]T,
2017-12-21 21:50:30 -08:00
\\ };
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn function_with_return_type_type() void {
2017-04-19 01:12:22 -07:00
\\ var list: List(i32) = undefined;
\\ list.length = 10;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:7: error: unable to evaluate constant expression " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:16:19: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" bogus method call on slice " ,
2017-04-19 01:12:22 -07:00
\\var self = "aoeu";
2018-01-25 01:10:11 -08:00
\\fn f(m: []const u8) void {
2017-05-19 07:39:59 -07:00
\\ m.copy(u8, self[0..], m);
2017-04-19 01:12:22 -07:00
\\}
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(f)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:6: error: no member named 'copy' in '[]const u8' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" wrong number of arguments for method fn call " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2018-05-31 07:56:59 -07:00
\\ fn method(self: *const Foo, a: i32) void {}
2017-04-19 01:12:22 -07:00
\\};
2018-05-31 07:56:59 -07:00
\\fn f(foo: *const Foo) void {
2017-04-19 01:12:22 -07:00
\\
\\ foo.method(1, 2);
\\}
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(f)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:15: error: expected 2 arguments, found 3 " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" assign through constant pointer " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2019-11-19 17:29:08 -08:00
\\ var cstr = "Hat";
2017-04-19 01:12:22 -07:00
\\ cstr[0] = 'W';
\\}
2018-05-28 17:23:55 -07:00
,
2019-08-02 13:09:40 -07:00
" tmp.zig:3:13: error: cannot assign to constant " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" assign through constant slice " ,
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ var cstr: []const u8 = "Hat";
\\ cstr[0] = 'W';
\\}
2018-05-28 17:23:55 -07:00
,
2019-08-02 13:09:40 -07:00
" tmp.zig:3:13: error: cannot assign to constant " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" main function with bogus args type " ,
2018-02-07 23:08:45 -08:00
\\pub fn main(args: [][]bogus) !void {}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:23: error: use of undeclared identifier 'bogus' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" misspelled type with pointer only reference " ,
2017-04-19 01:12:22 -07:00
\\const JasonHM = u8;
2018-05-31 07:56:59 -07:00
\\const JasonList = *JsonNode;
2017-04-19 01:12:22 -07:00
\\
2018-11-13 05:08:37 -08:00
\\const JsonOA = union(enum) {
2017-04-19 01:12:22 -07:00
\\ JSONArray: JsonList,
\\ JSONObject: JasonHM,
\\};
\\
2018-11-13 05:08:37 -08:00
\\const JsonType = union(enum) {
2017-04-19 01:12:22 -07:00
\\ JSONNull: void,
\\ JSONInteger: isize,
\\ JSONDouble: f64,
\\ JSONBool: bool,
\\ JSONString: []u8,
2017-12-03 17:43:56 -08:00
\\ JSONArray: void,
\\ JSONObject: void,
2017-04-19 01:12:22 -07:00
\\};
\\
2018-11-13 05:08:37 -08:00
\\pub const JsonNode = struct {
2017-04-19 01:12:22 -07:00
\\ kind: JsonType,
\\ jobject: ?JsonOA,
\\};
\\
2018-01-25 01:10:11 -08:00
\\fn foo() void {
2017-04-19 01:12:22 -07:00
\\ var jll: JasonList = undefined;
\\ jll.init(1234);
2018-11-13 05:08:37 -08:00
\\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:16: error: use of undeclared identifier 'JsonList' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" method call with first arg type primitive " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2017-04-19 01:12:22 -07:00
\\ x: i32,
\\
2018-01-25 01:10:11 -08:00
\\ fn init(x: i32) Foo {
2018-11-13 05:08:37 -08:00
\\ return Foo {
2017-04-19 01:12:22 -07:00
\\ .x = x,
2017-12-21 21:50:30 -08:00
\\ };
2017-04-19 01:12:22 -07:00
\\ }
\\};
\\
2018-01-25 01:10:11 -08:00
\\export fn f() void {
2017-04-19 01:12:22 -07:00
\\ const derp = Foo.init(3);
\\
\\ derp.init();
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:14:5: error: expected type 'i32', found 'Foo' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" method call with first arg type wrong container " ,
2018-11-13 05:08:37 -08:00
\\pub const List = struct {
2017-04-19 01:12:22 -07:00
\\ len: usize,
2018-05-31 07:56:59 -07:00
\\ allocator: *Allocator,
2017-04-19 01:12:22 -07:00
\\
2018-05-31 07:56:59 -07:00
\\ pub fn init(allocator: *Allocator) List {
2018-11-13 05:08:37 -08:00
\\ return List {
2017-04-19 01:12:22 -07:00
\\ .len = 0,
\\ .allocator = allocator,
2017-12-21 21:50:30 -08:00
\\ };
2017-04-19 01:12:22 -07:00
\\ }
\\};
\\
2018-11-13 05:08:37 -08:00
\\pub var global_allocator = Allocator {
2017-04-19 01:12:22 -07:00
\\ .field = 1234,
\\};
\\
2018-11-13 05:08:37 -08:00
\\pub const Allocator = struct {
2017-04-19 01:12:22 -07:00
\\ field: i32,
\\};
\\
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-19 01:12:22 -07:00
\\ var x = List.init(&global_allocator);
\\ x.init();
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:23:5: error: expected type '*Allocator', found '*List' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" binary not on number literal " ,
2017-04-19 01:12:22 -07:00
\\const TINY_QUANTUM_SHIFT = 4;
\\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
\\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2017-12-21 21:50:30 -08:00
cases . addCase ( x : {
2018-05-28 17:23:55 -07:00
const tc = cases . create (
" multiple files with private function error " ,
\\const foo = @import("foo.zig",);
2017-04-19 01:12:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\export fn callPrivFunction() void {
2017-04-19 01:12:22 -07:00
\\ foo.privateFunction();
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:8: error: 'privateFunction' is private " ,
2018-05-28 17:23:55 -07:00
" foo.zig:1:1: note: declared here " ,
) ;
2017-04-19 01:12:22 -07:00
tc . addSourceFile ( " foo.zig " ,
2018-01-25 01:10:11 -08:00
\\fn privateFunction() void { }
2017-04-19 01:12:22 -07:00
) ;
2017-12-21 21:50:30 -08:00
break : x tc ;
2017-04-19 01:12:22 -07:00
} ) ;
2018-05-28 17:23:55 -07:00
cases . add (
" container init with non-type " ,
2017-04-19 01:12:22 -07:00
\\const zero: i32 = 0;
2018-11-13 05:08:37 -08:00
\\const a = zero{1};
2017-04-19 01:12:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(a)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:11: error: expected type 'type', found 'i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" assign to constant field " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2017-04-19 01:12:22 -07:00
\\ field: i32,
\\};
2018-01-25 01:10:11 -08:00
\\export fn derp() void {
2018-11-13 05:08:37 -08:00
\\ const f = Foo {.field = 1234,};
2017-04-19 01:12:22 -07:00
\\ f.field = 0;
\\}
2018-05-28 17:23:55 -07:00
,
2019-08-02 13:09:40 -07:00
" tmp.zig:6:15: error: cannot assign to constant " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" return from defer expression " ,
2018-01-31 19:48:40 -08:00
\\pub fn testTrickyDefer() !void {
2018-01-07 14:28:20 -08:00
\\ defer canFail() catch {};
2017-04-19 01:12:22 -07:00
\\
2018-01-07 13:51:46 -08:00
\\ defer try canFail();
2017-04-19 01:12:22 -07:00
\\
2018-06-09 22:13:51 -07:00
\\ const a = maybeInt() orelse return;
2017-04-19 01:12:22 -07:00
\\}
\\
2018-11-13 05:08:37 -08:00
\\fn canFail() anyerror!void { }
2017-04-19 01:12:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\pub fn maybeInt() ?i32 {
2017-04-19 01:12:22 -07:00
\\ return 0;
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:11: error: cannot return from defer expression " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" attempt to access var args out of bounds " ,
2018-01-25 01:10:11 -08:00
\\fn add(args: ...) i32 {
2017-12-21 21:50:30 -08:00
\\ return args[0] + args[1];
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\fn foo() i32 {
2019-11-06 20:25:57 -08:00
\\ return add(@as(i32, 1234));
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:26: error: index 1 outside argument list of size 1 " ,
2019-08-26 19:38:45 -07:00
" tmp.zig:6:15: note: called from here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" pass integer literal to var args " ,
2018-01-25 01:10:11 -08:00
\\fn add(args: ...) i32 {
2019-11-06 20:25:57 -08:00
\\ var sum = @as(i32, 0);
2017-05-03 15:12:07 -07:00
\\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) {
2017-04-19 01:12:22 -07:00
\\ sum += args[i];
\\ }}
\\ return sum;
\\}
\\
2018-01-25 01:10:11 -08:00
\\fn bar() i32 {
2017-12-21 21:50:30 -08:00
\\ return add(1, 2, 3, 4);
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(bar)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:10:16: error: compiler bug: integer and float literals in var args function must be casted " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" assign too big number to u16 " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-19 01:12:22 -07:00
\\ var vga_mem: u16 = 0xB8000;
\\}
2018-05-28 17:23:55 -07:00
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" global variable alignment non power of 2 " ,
2017-08-30 01:54:33 -07:00
\\const some_data: [100]u8 align(3) = undefined;
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(some_data)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:32: error: alignment value 3 is not a power of 2 " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-29 04:30:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" function alignment non power of 2 " ,
2018-01-25 01:10:11 -08:00
\\extern fn foo() align(3) void;
\\export fn entry() void { return foo(); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:23: error: alignment value 3 is not a power of 2 " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" compile log " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2018-05-28 17:23:55 -07:00
\\ comptime bar(12, "hi",);
2017-04-19 01:12:22 -07:00
\\}
2018-01-25 01:10:11 -08:00
\\fn bar(a: i32, b: []const u8) void {
2018-05-28 17:23:55 -07:00
\\ @compileLog("begin",);
2017-04-19 01:12:22 -07:00
\\ @compileLog("a", a, "b", b);
2018-05-28 17:23:55 -07:00
\\ @compileLog("end",);
2017-04-19 01:12:22 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: found compile log statement " ,
" tmp.zig:6:5: error: found compile log statement " ,
" tmp.zig:7:5: error: found compile log statement " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" casting bit offset pointer to regular pointer " ,
2018-11-13 05:08:37 -08:00
\\const BitField = packed struct {
2017-04-19 01:12:22 -07:00
\\ a: u3,
\\ b: u3,
\\ c: u2,
\\};
\\
2018-05-31 07:56:59 -07:00
\\fn foo(bit_field: *const BitField) u3 {
2017-04-19 01:12:22 -07:00
\\ return bar(&bit_field.b);
\\}
\\
2018-05-31 07:56:59 -07:00
\\fn bar(x: *const u3) u3 {
2018-05-17 20:21:44 -07:00
\\ return x.*;
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2018-05-28 17:23:55 -07:00
,
2019-11-12 14:59:24 -08:00
" tmp.zig:8:16: error: expected type '*const u3', found '*align(:3:1) const u3' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" referring to a struct that is invalid " ,
2018-11-13 05:08:37 -08:00
\\const UsbDeviceRequest = struct {
2017-04-19 01:12:22 -07:00
\\ Type: u8,
\\};
\\
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-19 01:12:22 -07:00
\\ comptime assert(@sizeOf(UsbDeviceRequest) == 0x8);
\\}
\\
2018-01-25 01:10:11 -08:00
\\fn assert(ok: bool) void {
2017-04-19 01:12:22 -07:00
\\ if (!ok) unreachable;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:10:14: error: unable to evaluate constant expression " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:6:20: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" control flow uses comptime var at runtime " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-19 01:12:22 -07:00
\\ comptime var i = 0;
2017-05-03 15:12:07 -07:00
\\ while (i < 5) : (i += 1) {
2017-04-19 01:12:22 -07:00
\\ bar();
\\ }
\\}
\\
2018-01-25 01:10:11 -08:00
\\fn bar() void { }
2017-04-19 01:12:22 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime " ,
" tmp.zig:3:24: note: compile-time variable assigned here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" ignored return value " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-19 01:12:22 -07:00
\\ bar();
\\}
2018-01-25 01:10:11 -08:00
\\fn bar() i32 { return 0; }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:8: error: expression value is ignored " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" ignored assert-err-ok return value " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2018-01-08 21:07:01 -08:00
\\ bar() catch unreachable;
2017-04-23 21:49:42 -07:00
\\}
2018-11-13 05:08:37 -08:00
\\fn bar() anyerror!i32 { return 0; }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:11: error: expression value is ignored " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-23 21:49:42 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" ignored statement value " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-23 21:49:42 -07:00
\\ 1;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: expression value is ignored " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-23 21:49:42 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" ignored comptime statement value " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-23 21:49:42 -07:00
\\ comptime {1;}
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: expression value is ignored " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-23 21:49:42 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" ignored comptime value " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-23 21:49:42 -07:00
\\ comptime 1;
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: expression value is ignored " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-23 21:49:42 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" ignored defered statement value " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-23 21:49:42 -07:00
\\ defer {1;}
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:12: error: expression value is ignored " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-23 21:49:42 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" ignored defered function call " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-23 22:33:06 -07:00
\\ defer bar();
\\}
2018-11-13 05:08:37 -08:00
\\fn bar() anyerror!i32 { return 0; }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:14: error: expression value is ignored " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-23 22:33:06 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" dereference an array " ,
2017-04-19 01:12:22 -07:00
\\var s_buffer: [10]u8 = undefined;
2018-01-25 01:10:11 -08:00
\\pub fn pass(in: []u8) []u8 {
2017-04-19 01:12:22 -07:00
\\ var out = &s_buffer;
2018-06-03 22:09:15 -07:00
\\ out.*.* = in[0];
2018-05-17 20:21:44 -07:00
\\ return out.*[0..1];
2017-04-19 01:12:22 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(pass)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" pass const ptr to mutable ptr fn " ,
2018-01-25 01:10:11 -08:00
\\fn foo() bool {
2019-11-08 12:56:21 -08:00
\\ const a = @as([]const u8, "a",);
2017-04-19 01:12:22 -07:00
\\ const b = &a;
\\ return ptrEql(b, b);
\\}
2018-05-31 07:56:59 -07:00
\\fn ptrEql(a: *[]const u8, b: *[]const u8) bool {
2017-04-19 01:12:22 -07:00
\\ return true;
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2017-12-21 21:50:30 -08:00
cases . addCase ( x : {
2018-05-28 17:23:55 -07:00
const tc = cases . create (
" export collision " ,
\\const foo = @import("foo.zig",);
2017-12-18 23:39:43 -08:00
\\
2018-01-25 01:10:11 -08:00
\\export fn bar() usize {
2017-12-18 23:39:43 -08:00
\\ return foo.baz;
\\}
,
2018-11-13 05:08:37 -08:00
" foo.zig:1:1: error: exported symbol collision: 'bar' " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:1: note: other symbol here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-18 23:39:43 -08:00
tc . addSourceFile ( " foo.zig " ,
2018-01-25 01:10:11 -08:00
\\export fn bar() void {}
2017-12-18 23:39:43 -08:00
\\pub const baz = 1234;
) ;
2017-12-21 21:50:30 -08:00
break : x tc ;
2017-12-18 23:39:43 -08:00
} ) ;
2018-05-28 17:23:55 -07:00
cases . add (
" implicit cast from array to mutable slice " ,
2017-04-19 01:12:22 -07:00
\\var global_array: [10]i32 = undefined;
2018-01-25 01:10:11 -08:00
\\fn foo(param: []i32) void {}
\\export fn entry() void {
2017-04-19 01:12:22 -07:00
\\ foo(global_array);
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:9: error: expected type '[]i32', found '[10]i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" ptrcast to non-pointer " ,
2018-05-31 07:56:59 -07:00
\\export fn entry(a: *i32) usize {
2017-04-21 07:39:13 -07:00
\\ return @ptrCast(usize, a);
2017-04-19 01:12:22 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:21: error: expected pointer, found 'usize' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" asm at compile time " ,
2017-04-19 01:12:22 -07:00
\\comptime {
\\ doSomeAsm();
\\}
\\
2018-01-25 01:10:11 -08:00
\\fn doSomeAsm() void {
2017-04-19 01:12:22 -07:00
\\ asm volatile (
\\ \\.globl aoeu;
\\ \\.type aoeu, @function;
\\ \\.set aoeu, derp;
\\ );
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:5: error: unable to evaluate constant expression " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid member of builtin enum " ,
\\const builtin = @import("builtin",);
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-05-01 10:12:38 -07:00
\\ const foo = builtin.Arch.x86;
2017-04-19 01:12:22 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
`@import("std").builtin`. The target-related types are moved
to `std.Target`. This allows the data types to have methods, such as
`std.Target.current.isDarwin()`.
* `std.os.windows.subsystem` is moved to
`std.Target.current.subsystem`.
* Remove the concept of the panic package from the compiler
implementation. Instead, `std.builtin.panic` is always the panic
function. It checks for `@hasDecl(@import("root"), "panic")`,
or else provides a default implementation.
This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 15:43:24 -07:00
" tmp.zig:3:29: error: container 'std.target.Arch' has no member called 'x86' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" int to ptr of 0 bits " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-04-19 01:12:22 -07:00
\\ var x: usize = 0x1000;
2018-05-31 07:56:59 -07:00
\\ var y: *void = @intToPtr(*void, x);
2017-04-19 01:12:22 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @fieldParentPtr - non struct " ,
2017-04-19 01:12:22 -07:00
\\const Foo = i32;
2018-05-31 07:56:59 -07:00
\\export fn foo(a: *i32) *Foo {
2017-04-19 01:12:22 -07:00
\\ return @fieldParentPtr(Foo, "a", a);
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:28: error: expected struct type, found 'i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @fieldParentPtr - bad field name " ,
2018-11-13 05:08:37 -08:00
\\const Foo = extern struct {
2017-04-19 01:12:22 -07:00
\\ derp: i32,
\\};
2018-05-31 07:56:59 -07:00
\\export fn foo(a: *i32) *Foo {
2017-04-19 01:12:22 -07:00
\\ return @fieldParentPtr(Foo, "a", a);
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:33: error: struct 'Foo' has no field 'a' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @fieldParentPtr - field pointer is not pointer " ,
2018-11-13 05:08:37 -08:00
\\const Foo = extern struct {
2017-04-19 01:12:22 -07:00
\\ a: i32,
\\};
2018-05-31 07:56:59 -07:00
\\export fn foo(a: i32) *Foo {
2017-04-19 01:12:22 -07:00
\\ return @fieldParentPtr(Foo, "a", a);
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:38: error: expected pointer, found 'i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @fieldParentPtr - comptime field ptr not based on struct " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2017-04-19 01:12:22 -07:00
\\ a: i32,
\\ b: i32,
\\};
2018-11-13 05:08:37 -08:00
\\const foo = Foo { .a = 1, .b = 2, };
2017-04-19 01:12:22 -07:00
\\
\\comptime {
2018-05-31 07:56:59 -07:00
\\ const field_ptr = @intToPtr(*i32, 0x1234);
2017-04-19 01:12:22 -07:00
\\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:9:55: error: pointer value not based on parent struct " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @fieldParentPtr - comptime wrong field index " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2017-04-19 01:12:22 -07:00
\\ a: i32,
\\ b: i32,
\\};
2018-11-13 05:08:37 -08:00
\\const foo = Foo { .a = 1, .b = 2, };
2017-04-19 01:12:22 -07:00
\\
\\comptime {
\\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a);
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
2018-09-07 14:43:01 -07:00
" @byteOffsetOf - non struct " ,
2017-04-20 07:57:41 -07:00
\\const Foo = i32;
2018-01-25 01:10:11 -08:00
\\export fn foo() usize {
2018-09-07 14:43:01 -07:00
\\ return @byteOffsetOf(Foo, "a",);
2017-04-20 07:57:41 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:26: error: expected struct type, found 'i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-20 07:57:41 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
2018-09-07 14:43:01 -07:00
" @byteOffsetOf - bad field name " ,
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2017-04-20 07:57:41 -07:00
\\ derp: i32,
\\};
2018-01-25 01:10:11 -08:00
\\export fn foo() usize {
2018-09-07 14:43:01 -07:00
\\ return @byteOffsetOf(Foo, "a",);
2017-04-20 07:57:41 -07:00
\\}
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:31: error: struct 'Foo' has no field 'a' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-20 07:57:41 -07:00
2018-05-28 17:23:55 -07:00
cases . addExe (
" missing main fn in executable " ,
2017-04-19 01:12:22 -07:00
\\
2018-05-28 17:23:55 -07:00
,
2019-03-01 12:35:29 -08:00
" error: root source file has no member called 'main' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-19 01:12:22 -07:00
2018-05-28 17:23:55 -07:00
cases . addExe (
" private main fn " ,
2018-01-25 01:10:11 -08:00
\\fn main() void {}
2017-04-19 01:12:22 -07:00
,
" error: 'main' is private " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:1: note: declared here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-22 09:54:00 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" setting a section on a local variable " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() i32 {
2018-11-16 22:38:35 -08:00
\\ var foo: i32 linksection(".text2") = 1234;
2017-12-18 23:39:43 -08:00
\\ return foo;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:30: error: cannot set section of local variable 'foo' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-18 23:39:43 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" returning address of local variable - simple " ,
2018-05-31 07:56:59 -07:00
\\export fn foo() *i32 {
2017-04-27 16:40:35 -07:00
\\ var a: i32 = undefined;
\\ return &a;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:13: error: function returns address of local variable " ,
2018-05-28 17:23:55 -07:00
) ;
2017-04-27 20:40:43 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" returning address of local variable - phi " ,
2018-05-31 07:56:59 -07:00
\\export fn foo(c: bool) *i32 {
2017-04-27 20:40:43 -07:00
\\ var a: i32 = undefined;
\\ var b: i32 = undefined;
\\ return if (c) &a else &b;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:12: error: function returns address of local variable " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-03 13:13:22 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" inner struct member shadowing outer struct member " ,
2018-01-25 01:10:11 -08:00
\\fn A() type {
2018-11-13 05:08:37 -08:00
\\ return struct {
2017-05-03 13:13:22 -07:00
\\ b: B(),
\\
2018-09-13 13:34:33 -07:00
\\ const Self = @This();
2017-05-03 13:13:22 -07:00
\\
2018-01-25 01:10:11 -08:00
\\ fn B() type {
2018-11-13 05:08:37 -08:00
\\ return struct {
2018-09-13 13:34:33 -07:00
\\ const Self = @This();
2017-12-21 21:50:30 -08:00
\\ };
2017-05-03 13:13:22 -07:00
\\ }
2017-12-21 21:50:30 -08:00
\\ };
2017-05-03 13:13:22 -07:00
\\}
\\comptime {
\\ assert(A().B().Self != A().Self);
\\}
2018-01-25 01:10:11 -08:00
\\fn assert(ok: bool) void {
2017-05-03 13:13:22 -07:00
\\ if (!ok) unreachable;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:9:17: error: redefinition of 'Self' " ,
" tmp.zig:5:9: note: previous definition is here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-04 07:18:01 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
2018-06-09 20:42:14 -07:00
" while expected bool, got optional " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-05-04 07:18:01 -07:00
\\ while (bar()) {}
\\}
2018-01-25 01:10:11 -08:00
\\fn bar() ?i32 { return 1; }
2017-05-04 07:18:01 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: expected type 'bool', found '?i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-04 07:18:01 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" while expected bool, got error union " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-05-04 07:18:01 -07:00
\\ while (bar()) {}
\\}
2018-11-13 05:08:37 -08:00
\\fn bar() anyerror!i32 { return 1; }
2017-05-04 07:18:01 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-04 07:18:01 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
2018-06-09 20:42:14 -07:00
" while expected optional, got bool " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-05-04 07:18:01 -07:00
\\ while (bar()) |x| {}
\\}
2018-01-25 01:10:11 -08:00
\\fn bar() bool { return true; }
2017-05-04 07:18:01 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: expected optional type, found 'bool' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-04 07:18:01 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
2018-06-09 20:42:14 -07:00
" while expected optional, got error union " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-05-04 07:18:01 -07:00
\\ while (bar()) |x| {}
\\}
2018-11-13 05:08:37 -08:00
\\fn bar() anyerror!i32 { return 1; }
2017-05-04 07:18:01 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: expected optional type, found 'anyerror!i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-04 07:18:01 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" while expected error union, got bool " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-05-04 07:18:01 -07:00
\\ while (bar()) |x| {} else |err| {}
\\}
2018-01-25 01:10:11 -08:00
\\fn bar() bool { return true; }
2017-05-04 07:18:01 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: expected error union type, found 'bool' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-04 07:18:01 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
2018-06-09 20:42:14 -07:00
" while expected error union, got optional " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-05-04 07:18:01 -07:00
\\ while (bar()) |x| {} else |err| {}
\\}
2018-01-25 01:10:11 -08:00
\\fn bar() ?i32 { return 1; }
2017-05-04 07:18:01 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: expected error union type, found '?i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-04 12:00:25 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" inline fn calls itself indirectly " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-05-04 12:00:25 -07:00
\\ bar();
\\}
2018-01-25 01:10:11 -08:00
\\inline fn bar() void {
2017-05-04 12:00:25 -07:00
\\ baz();
\\ quux();
\\}
2018-01-25 01:10:11 -08:00
\\inline fn baz() void {
2017-05-04 12:00:25 -07:00
\\ bar();
\\ quux();
\\}
2018-01-25 01:10:11 -08:00
\\extern fn quux() void;
2017-05-04 12:00:25 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:1: error: unable to inline function " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-04 12:00:25 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" save reference to inline function " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-08-08 14:38:25 -07:00
\\ quux(@ptrToInt(bar));
2017-05-04 12:00:25 -07:00
\\}
2018-01-25 01:10:11 -08:00
\\inline fn bar() void { }
\\extern fn quux(usize) void;
2017-05-04 12:00:25 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:1: error: unable to inline function " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-06 20:13:12 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" signed integer division " ,
2018-01-25 01:10:11 -08:00
\\export fn foo(a: i32, b: i32) i32 {
2017-12-21 21:50:30 -08:00
\\ return a / b;
2017-05-06 20:13:12 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-06 20:13:12 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" signed integer remainder division " ,
2018-01-25 01:10:11 -08:00
\\export fn foo(a: i32, b: i32) i32 {
2017-12-21 21:50:30 -08:00
\\ return a % b;
2017-05-06 20:13:12 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-09 21:21:27 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" compile-time division by zero " ,
2017-05-14 10:07:45 -07:00
\\comptime {
\\ const a: i32 = 1;
\\ const b: i32 = 0;
\\ const c = a / b;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:17: error: division by zero " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-14 10:07:45 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" compile-time remainder division by zero " ,
2017-05-14 10:07:45 -07:00
\\comptime {
\\ const a: i32 = 1;
\\ const b: i32 = 0;
\\ const c = a % b;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:17: error: division by zero " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-16 14:04:35 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @setRuntimeSafety twice for same scope " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2018-01-24 22:46:12 -08:00
\\ @setRuntimeSafety(false);
\\ @setRuntimeSafety(false);
2017-05-20 20:06:32 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: runtime safety set twice for same scope " ,
" tmp.zig:2:5: note: first set here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-20 20:06:32 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @setFloatMode twice for same scope " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2018-09-13 12:46:34 -07:00
\\ @setFloatMode(@import("builtin").FloatMode.Optimized);
\\ @setFloatMode(@import("builtin").FloatMode.Optimized);
2017-05-20 20:06:32 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: float mode set twice for same scope " ,
" tmp.zig:2:5: note: first set here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-21 06:50:15 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" array access of type " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-05-21 06:50:15 -07:00
\\ var b: u8[40] = undefined;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:14: error: array access of non-array type 'type' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-21 07:41:57 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" cannot break out of defer expression " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-05-21 07:41:57 -07:00
\\ while (true) {
\\ defer {
\\ break;
\\ }
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:13: error: cannot break out of defer expression " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-21 07:41:57 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" cannot continue out of defer expression " ,
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2017-05-21 07:41:57 -07:00
\\ while (true) {
\\ defer {
\\ continue;
\\ }
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:13: error: cannot continue out of defer expression " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-21 07:59:09 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" calling a var args function only known at runtime " ,
2019-06-09 16:24:24 -07:00
\\var foos = [_]fn(...) void { foo1, foo2 };
2017-05-25 10:48:10 -07:00
\\
2018-01-25 01:10:11 -08:00
\\fn foo1(args: ...) void {}
\\fn foo2(args: ...) void {}
2017-05-25 10:48:10 -07:00
\\
2018-01-31 19:48:40 -08:00
\\pub fn main() !void {
2017-05-25 10:48:10 -07:00
\\ foos[0]();
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:7:9: error: calling a generic function requires compile-time known function value " ,
2018-05-28 17:23:55 -07:00
) ;
2017-05-26 11:39:18 -07:00
2018-11-13 05:08:37 -08:00
cases . add (
" calling a generic function only known at runtime " ,
2019-06-09 16:24:24 -07:00
\\var foos = [_]fn(var) void { foo1, foo2 };
2018-11-13 05:08:37 -08:00
\\
\\fn foo1(arg: var) void {}
\\fn foo2(arg: var) void {}
\\
\\pub fn main() !void {
\\ foos[0](true);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:7:9: error: calling a generic function requires compile-time known function value " ,
2018-11-13 05:08:37 -08:00
) ;
2018-05-28 17:23:55 -07:00
cases . add (
" @compileError shows traceback of references that caused it " ,
\\const foo = @compileError("aoeu",);
2017-06-03 12:09:40 -07:00
\\
\\const bar = baz + foo;
\\const baz = 1;
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() i32 {
2017-06-03 12:09:40 -07:00
\\ return bar;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:13: error: aoeu " ,
" tmp.zig:3:19: note: referenced here " ,
" tmp.zig:7:12: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-06 23:06:06 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" float literal too large error " ,
2017-08-06 23:06:06 -07:00
\\comptime {
2019-03-22 11:56:03 -07:00
\\ const a = 0x1.0p18495;
2017-08-06 23:06:06 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: float literal out of range of any type " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-06 23:06:06 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" float literal too small error (denormal) " ,
2017-08-06 23:06:06 -07:00
\\comptime {
2019-03-22 11:56:03 -07:00
\\ const a = 0x1.0p-19000;
2017-08-06 23:06:06 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: float literal out of range of any type " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-07 12:57:41 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" explicit cast float literal to integer when there is a fraction component " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() i32 {
2019-11-06 20:25:57 -08:00
\\ return @as(i32, 12.34);
2017-08-07 12:57:41 -07:00
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-08 14:38:25 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" non pointer given to @ptrToInt " ,
2018-01-25 01:10:11 -08:00
\\export fn entry(x: i32) usize {
2017-12-21 21:50:30 -08:00
\\ return @ptrToInt(x);
2017-08-08 14:38:25 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:22: error: expected pointer, found 'i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-09 07:09:38 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @shlExact shifts out 1 bits " ,
2017-08-09 07:09:38 -07:00
\\comptime {
2019-11-06 20:25:57 -08:00
\\ const x = @shlExact(@as(u8, 0b01010101), 2);
2017-08-09 07:09:38 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: operation caused overflow " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-09 07:09:38 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @shrExact shifts out 1 bits " ,
2017-08-09 07:09:38 -07:00
\\comptime {
2019-11-06 20:25:57 -08:00
\\ const x = @shrExact(@as(u8, 0b10101010), 2);
2017-08-09 07:09:38 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:15: error: exact shift shifted out 1 bits " ,
2018-05-28 17:23:55 -07:00
) ;
bit shifting safety
* add u3, u4, u5, u6, u7 and i3, i4, i5, i6, i7
* shift operations shift amount parameter type is
integer with log2 bit width of other param
- This enforces not violating undefined behavior on
shift amount >= bit width with the type system
* clean up math.log, math.ln, math.log2, math.log10
closes #403
2017-08-18 22:32:15 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" shifting without int type or comptime known " ,
2018-01-25 01:10:11 -08:00
\\export fn entry(x: u8) u8 {
bit shifting safety
* add u3, u4, u5, u6, u7 and i3, i4, i5, i6, i7
* shift operations shift amount parameter type is
integer with log2 bit width of other param
- This enforces not violating undefined behavior on
shift amount >= bit width with the type system
* clean up math.log, math.ln, math.log2, math.log10
closes #403
2017-08-18 22:32:15 -07:00
\\ return 0x11 << x;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known " ,
2018-05-28 17:23:55 -07:00
) ;
bit shifting safety
* add u3, u4, u5, u6, u7 and i3, i4, i5, i6, i7
* shift operations shift amount parameter type is
integer with log2 bit width of other param
- This enforces not violating undefined behavior on
shift amount >= bit width with the type system
* clean up math.log, math.ln, math.log2, math.log10
closes #403
2017-08-18 22:32:15 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" shifting RHS is log2 of LHS int bit width " ,
2018-01-25 01:10:11 -08:00
\\export fn entry(x: u8, y: u8) u8 {
bit shifting safety
* add u3, u4, u5, u6, u7 and i3, i4, i5, i6, i7
* shift operations shift amount parameter type is
integer with log2 bit width of other param
- This enforces not violating undefined behavior on
shift amount >= bit width with the type system
* clean up math.log, math.ln, math.log2, math.log10
closes #403
2017-08-18 22:32:15 -07:00
\\ return x << y;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:17: error: expected type 'u3', found 'u8' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-18 23:02:25 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" globally shadowing a primitive type " ,
2017-08-18 23:02:25 -07:00
\\const u16 = @intType(false, 8);
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-08-18 23:02:25 -07:00
\\ const a: u16 = 300;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:1: error: declaration shadows primitive type 'u16' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-29 12:19:15 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicitly increasing pointer alignment " ,
2018-11-13 05:08:37 -08:00
\\const Foo = packed struct {
2017-08-29 12:19:15 -07:00
\\ a: u8,
\\ b: u32,
\\};
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ var foo = Foo { .a = 1, .b = 10 };
2017-08-29 12:19:15 -07:00
\\ bar(&foo.b);
\\}
\\
2018-05-31 07:56:59 -07:00
\\fn bar(x: *u32) void {
2018-05-17 20:21:44 -07:00
\\ x.* += 1;
2017-08-29 12:19:15 -07:00
\\}
,
2019-11-12 14:59:24 -08:00
" tmp.zig:8:9: error: expected type '*u32', found '*align(1) u32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-29 12:19:15 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicitly increasing slice alignment " ,
2018-11-13 05:08:37 -08:00
\\const Foo = packed struct {
2017-08-29 12:19:15 -07:00
\\ a: u8,
\\ b: u32,
\\};
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ var foo = Foo { .a = 1, .b = 10 };
2017-08-29 12:19:15 -07:00
\\ foo.b += 1;
2019-11-08 12:56:21 -08:00
\\ bar(@as(*[1]u32, &foo.b)[0..]);
2017-08-29 12:19:15 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\fn bar(x: []u32) void {
2017-08-29 12:19:15 -07:00
\\ x[0] += 1;
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:9:9: error: cast increases pointer alignment " ,
" tmp.zig:9:26: note: '*align(1) u32' has alignment 1 " ,
" tmp.zig:9:9: note: '*[1]u32' has alignment 4 " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-29 13:52:31 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" increase pointer alignment in @ptrCast " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() u32 {
2019-06-09 16:24:24 -07:00
\\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04};
2018-05-31 07:56:59 -07:00
\\ const ptr = @ptrCast(*u32, &bytes[0]);
2018-05-17 20:21:44 -07:00
\\ return ptr.*;
2017-08-29 13:52:31 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:17: error: cast increases pointer alignment " ,
" tmp.zig:3:38: note: '*u8' has alignment 1 " ,
" tmp.zig:3:26: note: '*u32' has alignment 4 " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-29 20:33:25 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @alignCast expects pointer or slice " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2019-11-06 20:25:57 -08:00
\\ @alignCast(4, @as(u32, 3));
2017-08-29 20:33:25 -07:00
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:2:19: error: expected pointer or slice, found 'u32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-29 21:06:14 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" passing an under-aligned function pointer " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-08-29 21:06:14 -07:00
\\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
\\}
2018-01-25 01:10:11 -08:00
\\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void {
2017-08-29 21:06:14 -07:00
\\ if (ptr() != answer) unreachable;
\\}
2018-01-25 01:10:11 -08:00
\\fn alignedSmall() align(4) i32 { return 1234; }
2017-08-29 21:06:14 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-29 21:06:14 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" passing a not-aligned-enough pointer to cmpxchg " ,
2017-08-29 23:56:42 -07:00
\\const AtomicOrder = @import("builtin").AtomicOrder;
2018-01-25 01:10:11 -08:00
\\export fn entry() bool {
2017-08-30 01:54:33 -07:00
\\ var x: i32 align(1) = 1234;
2018-04-18 09:16:42 -07:00
\\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
2017-08-29 23:56:42 -07:00
\\ return x == 5678;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-29 23:56:42 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" wrong size to an array literal " ,
2017-08-31 13:30:46 -07:00
\\comptime {
2018-11-13 05:08:37 -08:00
\\ const array = [2]u8{1, 2, 3};
2017-08-31 13:30:46 -07:00
\\}
,
2019-06-25 16:03:56 -07:00
" tmp.zig:2:31: error: index 2 outside array of size 2 " ,
2018-05-28 17:23:55 -07:00
) ;
2017-08-31 13:30:46 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
2019-11-08 12:56:21 -08:00
" wrong pointer coerced to pointer to @OpaqueType() " ,
2017-09-05 15:51:07 -07:00
\\const Derp = @OpaqueType();
2018-05-31 07:56:59 -07:00
\\extern fn bar(d: *Derp) void;
2018-01-25 01:10:11 -08:00
\\export fn foo() void {
2019-11-06 20:25:57 -08:00
\\ var x = @as(u8, 1);
2018-05-31 07:56:59 -07:00
\\ bar(@ptrCast(*c_void, &x));
2017-09-05 15:51:07 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:9: error: expected type '*Derp', found '*c_void' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-09-05 15:51:07 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" non-const variables of things that require const variables " ,
2019-06-25 16:03:56 -07:00
\\export fn entry1() void {
2017-09-09 19:46:08 -07:00
\\ var m2 = &2;
2019-06-25 16:03:56 -07:00
\\}
\\export fn entry2() void {
2017-09-09 19:46:08 -07:00
\\ var a = undefined;
2019-06-25 16:03:56 -07:00
\\}
\\export fn entry3() void {
2017-09-09 19:46:08 -07:00
\\ var b = 1;
2019-06-25 16:03:56 -07:00
\\}
\\export fn entry4() void {
2017-09-09 19:46:08 -07:00
\\ var c = 1.0;
2019-06-25 16:03:56 -07:00
\\}
\\export fn entry5() void {
2018-09-13 13:34:33 -07:00
\\ var d = null;
2019-06-25 16:03:56 -07:00
\\}
\\export fn entry6(opaque: *Opaque) void {
2018-09-13 13:34:33 -07:00
\\ var e = opaque.*;
2019-06-25 16:03:56 -07:00
\\}
\\export fn entry7() void {
2018-09-13 13:34:33 -07:00
\\ var f = i32;
2019-06-25 16:03:56 -07:00
\\}
\\export fn entry8() void {
2018-11-13 05:08:37 -08:00
\\ var h = (Foo {}).bar;
2019-06-25 16:03:56 -07:00
\\}
\\export fn entry9() void {
2017-09-09 19:46:08 -07:00
\\ var z: noreturn = return;
\\}
2019-06-25 16:03:56 -07:00
\\const Opaque = @OpaqueType();
2018-11-13 05:08:37 -08:00
\\const Foo = struct {
2018-05-31 07:56:59 -07:00
\\ fn bar(self: *const Foo) void {}
2017-09-09 19:46:08 -07:00
\\};
,
2019-06-25 16:03:56 -07:00
" tmp.zig:2:4: error: variable of type '*comptime_int' must be const or comptime " ,
" tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:8:4: error: variable of type 'comptime_int' must be const or comptime " ,
2019-06-25 16:03:56 -07:00
" tmp.zig:11:4: error: variable of type 'comptime_float' must be const or comptime " ,
" tmp.zig:14:4: error: variable of type '(null)' must be const or comptime " ,
" tmp.zig:17:4: error: variable of type 'Opaque' not allowed " ,
" tmp.zig:20:4: error: variable of type 'type' must be const or comptime " ,
" tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime " ,
2019-11-08 12:56:21 -08:00
" tmp.zig:26:22: error: unreachable code " ,
2018-05-28 17:23:55 -07:00
) ;
2017-09-09 19:46:08 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" wrong types given to atomic order args in cmpxchg " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-09-10 11:03:15 -07:00
\\ var x: i32 = 1234;
2019-11-06 20:25:57 -08:00
\\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
2017-09-10 11:03:15 -07:00
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-09-10 11:03:15 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" wrong types given to @export " ,
2018-01-25 01:10:11 -08:00
\\extern fn entry() void { }
2017-12-18 23:39:43 -08:00
\\comptime {
2019-11-06 20:25:57 -08:00
\\ @export("entry", entry, @as(u32, 1234));
2017-12-18 23:39:43 -08:00
\\}
,
2019-11-08 12:56:21 -08:00
" tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-18 23:39:43 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" struct with invalid field " ,
\\const std = @import("std",);
2017-09-17 20:21:22 -07:00
\\const Allocator = std.mem.Allocator;
\\const ArrayList = std.ArrayList;
\\
2018-11-13 05:08:37 -08:00
\\const HeaderWeight = enum {
2017-09-17 20:21:22 -07:00
\\ H1, H2, H3, H4, H5, H6,
\\};
\\
\\const MdText = ArrayList(u8);
\\
2018-11-13 05:08:37 -08:00
\\const MdNode = union(enum) {
\\ Header: struct {
2017-09-17 20:21:22 -07:00
\\ text: MdText,
\\ weight: HeaderValue,
\\ },
\\};
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ const a = MdNode.Header {
2017-09-17 20:21:22 -07:00
\\ .text = MdText.init(&std.debug.global_allocator),
\\ .weight = HeaderWeight.H1,
\\ };
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-10-02 19:00:42 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @setAlignStack outside function " ,
2017-10-02 19:00:42 -07:00
\\comptime {
\\ @setAlignStack(16);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: @setAlignStack outside function " ,
2018-05-28 17:23:55 -07:00
) ;
2017-10-02 19:00:42 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @setAlignStack in naked function " ,
2018-01-25 01:10:11 -08:00
\\export nakedcc fn entry() void {
2017-10-02 19:00:42 -07:00
\\ @setAlignStack(16);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: @setAlignStack in naked function " ,
2018-05-28 17:23:55 -07:00
) ;
2017-10-02 19:00:42 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @setAlignStack in inline function " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-10-02 19:00:42 -07:00
\\ foo();
\\}
2018-01-25 01:10:11 -08:00
\\inline fn foo() void {
2017-10-02 19:00:42 -07:00
\\ @setAlignStack(16);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:5: error: @setAlignStack in inline function " ,
2018-05-28 17:23:55 -07:00
) ;
2017-10-02 19:00:42 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @setAlignStack set twice " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-10-02 19:00:42 -07:00
\\ @setAlignStack(16);
\\ @setAlignStack(16);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: alignstack set twice " ,
" tmp.zig:2:5: note: first set here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-10-06 09:41:14 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @setAlignStack too big " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-10-23 19:33:00 -07:00
\\ @setAlignStack(511 + 1);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256 " ,
2018-05-28 17:23:55 -07:00
) ;
2017-10-23 19:33:00 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" storing runtime value in compile time variable then using it " ,
2017-10-06 09:41:14 -07:00
\\const Mode = @import("builtin").Mode;
\\
2018-01-25 01:10:11 -08:00
\\fn Free(comptime filename: []const u8) TestCase {
2018-11-13 05:08:37 -08:00
\\ return TestCase {
2017-10-06 09:41:14 -07:00
\\ .filename = filename,
\\ .problem_type = ProblemType.Free,
2017-12-21 21:50:30 -08:00
\\ };
2017-10-06 09:41:14 -07:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\fn LibC(comptime filename: []const u8) TestCase {
2018-11-13 05:08:37 -08:00
\\ return TestCase {
2017-10-06 09:41:14 -07:00
\\ .filename = filename,
\\ .problem_type = ProblemType.LinkLibC,
2017-12-21 21:50:30 -08:00
\\ };
2017-10-06 09:41:14 -07:00
\\}
\\
2018-11-13 05:08:37 -08:00
\\const TestCase = struct {
2017-10-06 09:41:14 -07:00
\\ filename: []const u8,
\\ problem_type: ProblemType,
\\};
\\
2018-11-13 05:08:37 -08:00
\\const ProblemType = enum {
2017-10-06 09:41:14 -07:00
\\ Free,
\\ LinkLibC,
\\};
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2019-06-09 16:24:24 -07:00
\\ const tests = [_]TestCase {
2017-10-06 09:41:14 -07:00
\\ Free("001"),
\\ Free("002"),
\\ LibC("078"),
\\ Free("116"),
\\ Free("117"),
\\ };
\\
2019-06-09 16:24:24 -07:00
\\ for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| {
2017-10-06 09:41:14 -07:00
\\ inline for (tests) |test_case| {
\\ const foo = test_case.filename ++ ".zig";
\\ }
\\ }
\\}
,
2019-06-25 16:03:56 -07:00
" tmp.zig:37:29: error: cannot store runtime value in compile time variable " ,
2018-05-28 17:23:55 -07:00
) ;
2017-10-25 20:18:18 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" field access of opaque type " ,
2017-10-25 20:18:18 -07:00
\\const MyType = @OpaqueType();
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() bool {
2017-10-25 20:18:18 -07:00
\\ var x: i32 = 1;
2018-05-31 07:56:59 -07:00
\\ return bar(@ptrCast(*MyType, &x));
2017-10-25 20:18:18 -07:00
\\}
\\
2018-05-31 07:56:59 -07:00
\\fn bar(x: *MyType) bool {
2017-10-25 20:18:18 -07:00
\\ return x.blah;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:9:13: error: type '*MyType' does not support field access " ,
2018-05-28 17:23:55 -07:00
) ;
2017-10-26 07:00:23 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" carriage return special case " ,
2018-01-25 01:10:11 -08:00
" fn test() bool { \r \n " + +
2018-05-28 17:23:55 -07:00
" true \r \n " + +
" } \r \n " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:17: error: invalid carriage return, only ' \\ n' line endings are supported " ,
2018-05-28 17:23:55 -07:00
) ;
2019-07-04 22:40:19 -07:00
cases . add (
" invalid legacy unicode escape " ,
\\export fn entry() void {
\\ const a = '\U1234';
\\}
,
" tmp.zig:2:17: error: invalid character: 'U' " ,
) ;
cases . add (
" invalid empty unicode escape " ,
\\export fn entry() void {
\\ const a = '\u{}';
\\}
,
" tmp.zig:2:19: error: empty unicode escape sequence " ,
) ;
2018-05-28 17:23:55 -07:00
cases . add (
" non-printable invalid character " ,
2019-02-14 15:54:37 -08:00
" \xff \xfe " + +
2018-05-28 17:23:55 -07:00
\\fn test() bool {\r
\\ true\r
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:1: error: invalid character: ' \\ xff' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-10-26 07:00:23 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" non-printable invalid character with escape alternative " ,
2018-01-25 01:10:11 -08:00
" fn test() bool { \n " + +
2018-05-28 17:23:55 -07:00
" \t true \n " + +
" } \n " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:1: error: invalid character: ' \\ t' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-10-26 07:00:23 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @ArgType given non function parameter " ,
2017-11-04 13:19:43 -07:00
\\comptime {
\\ _ = @ArgType(i32, 3);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:18: error: expected function, found 'i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-11-04 13:19:43 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" @ArgType arg index out of bounds " ,
2017-11-04 13:19:43 -07:00
\\comptime {
\\ _ = @ArgType(@typeOf(add), 2);
\\}
2018-01-25 01:10:11 -08:00
\\fn add(a: i32, b: i32) i32 { return a + b; }
2017-11-04 13:19:43 -07:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments " ,
2018-05-28 17:23:55 -07:00
) ;
2017-11-06 19:07:19 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @memberType on unsupported type " ,
2017-11-06 19:07:19 -08:00
\\comptime {
\\ _ = @memberType(i32, 0);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:21: error: type 'i32' does not support @memberType " ,
2018-05-28 17:23:55 -07:00
) ;
2017-11-06 19:07:19 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @memberType on enum " ,
2017-12-03 17:43:56 -08:00
\\comptime {
\\ _ = @memberType(Foo, 0);
\\}
2018-11-13 05:08:37 -08:00
\\const Foo = enum {A,};
2017-12-03 17:43:56 -08:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:21: error: type 'Foo' does not support @memberType " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 17:43:56 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @memberType struct out of bounds " ,
2017-11-06 19:07:19 -08:00
\\comptime {
\\ _ = @memberType(Foo, 0);
\\}
2018-11-13 05:08:37 -08:00
\\const Foo = struct {};
2017-11-06 19:07:19 -08:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members " ,
2018-05-28 17:23:55 -07:00
) ;
2017-11-06 19:07:19 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @memberType union out of bounds " ,
2017-11-06 19:07:19 -08:00
\\comptime {
2017-12-02 19:31:42 -08:00
\\ _ = @memberType(Foo, 1);
2017-11-06 19:07:19 -08:00
\\}
2018-11-13 05:08:37 -08:00
\\const Foo = union {A: void,};
2017-11-06 19:07:19 -08:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members " ,
2018-05-28 17:23:55 -07:00
) ;
2017-11-06 19:07:19 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @memberName on unsupported type " ,
2017-11-06 19:07:19 -08:00
\\comptime {
\\ _ = @memberName(i32, 0);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:21: error: type 'i32' does not support @memberName " ,
2018-05-28 17:23:55 -07:00
) ;
2017-11-06 19:07:19 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @memberName struct out of bounds " ,
2017-11-06 19:07:19 -08:00
\\comptime {
\\ _ = @memberName(Foo, 0);
\\}
2018-11-13 05:08:37 -08:00
\\const Foo = struct {};
2017-11-06 19:07:19 -08:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members " ,
2018-05-28 17:23:55 -07:00
) ;
2017-11-06 19:07:19 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @memberName enum out of bounds " ,
2017-11-06 19:07:19 -08:00
\\comptime {
2017-12-02 19:31:42 -08:00
\\ _ = @memberName(Foo, 1);
2017-11-06 19:07:19 -08:00
\\}
2018-11-13 05:08:37 -08:00
\\const Foo = enum {A,};
2017-11-06 19:07:19 -08:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members " ,
2018-05-28 17:23:55 -07:00
) ;
2017-11-09 08:30:39 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @memberName union out of bounds " ,
2017-12-03 17:43:56 -08:00
\\comptime {
\\ _ = @memberName(Foo, 1);
\\}
2018-11-13 05:08:37 -08:00
\\const Foo = union {A:i32,};
2017-12-03 17:43:56 -08:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 17:43:56 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" calling var args extern function, passing array instead of pointer " ,
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2019-11-20 13:08:01 -08:00
\\ foo("hello".*,);
2017-11-09 08:30:39 -08:00
\\}
2018-05-31 07:56:59 -07:00
\\pub extern fn foo(format: *const u8, ...) void;
2017-11-09 08:30:39 -08:00
,
2019-11-23 23:14:21 -08:00
" tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-11-25 15:16:33 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" constant inside comptime function has compile error " ,
2017-11-25 15:16:33 -08:00
\\const ContextAllocator = MemoryPool(usize);
\\
2018-01-25 01:10:11 -08:00
\\pub fn MemoryPool(comptime T: type) type {
2018-05-28 17:23:55 -07:00
\\ const free_list_t = @compileError("aoeu",);
2017-11-25 15:16:33 -08:00
\\
2018-11-13 05:08:37 -08:00
\\ return struct {
2017-11-25 15:16:33 -08:00
\\ free_list: free_list_t,
2017-12-21 21:50:30 -08:00
\\ };
2017-11-25 15:16:33 -08:00
\\}
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-11-25 15:16:33 -08:00
\\ var allocator: ContextAllocator = undefined;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:4:25: error: aoeu " ,
2019-08-26 15:35:36 -07:00
" tmp.zig:1:36: note: referenced here " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:12:20: note: referenced here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-11-30 18:46:02 -08:00
2019-05-10 10:28:13 -07:00
cases . add ( " specify enum tag type that is too small " ,
2018-11-13 05:08:37 -08:00
\\const Small = enum (u2) {
2017-11-30 18:46:02 -08:00
\\ One,
\\ Two,
\\ Three,
\\ Four,
\\ Five,
\\};
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-11-30 18:46:02 -08:00
\\ var x = Small.One;
\\}
2019-05-10 10:28:13 -07:00
, " tmp.zig:6:5: error: enumeration value 4 too large for type 'u2' " ) ;
2017-11-30 18:46:02 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" specify non-integer enum tag type " ,
2018-11-13 05:08:37 -08:00
\\const Small = enum (f32) {
2017-11-30 18:46:02 -08:00
\\ One,
\\ Two,
\\ Three,
\\};
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-11-30 18:46:02 -08:00
\\ var x = Small.One;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:21: error: expected integer, found 'f32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-02 14:12:37 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" implicitly casting enum to tag type " ,
2018-11-13 05:08:37 -08:00
\\const Small = enum(u2) {
2017-12-02 14:12:37 -08:00
\\ One,
\\ Two,
\\ Three,
\\ Four,
\\};
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-02 14:12:37 -08:00
\\ var x: u2 = Small.Two;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:9:22: error: expected type 'u2', found 'Small' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-02 14:12:37 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" explicitly casting non tag type to enum " ,
2018-11-13 05:08:37 -08:00
\\const Small = enum(u2) {
2017-12-02 14:12:37 -08:00
\\ One,
\\ Two,
\\ Three,
\\ Four,
\\};
\\
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2019-11-08 12:56:21 -08:00
\\ var y = @as(u3, 3);
2018-06-19 00:50:38 -07:00
\\ var x = @intToEnum(Small, y);
2017-12-02 14:12:37 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:10:31: error: expected type 'u2', found 'u3' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-02 14:12:37 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" union fields with value assignments " ,
2018-11-13 05:08:37 -08:00
\\const MultipleChoice = union {
2017-12-02 19:31:42 -08:00
\\ A: i32 = 20,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-03 21:56:27 -08:00
\\ var x: MultipleChoice = undefined;
2017-12-02 19:31:42 -08:00
\\}
,
2019-08-26 19:38:45 -07:00
" tmp.zig:2:14: error: untagged union field assignment " ,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:24: note: consider 'union(enum)' here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-02 19:31:42 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" enum with 0 fields " ,
2018-11-13 05:08:37 -08:00
\\const Foo = enum {};
2018-01-25 01:10:11 -08:00
\\export fn entry() usize {
2017-12-02 19:31:42 -08:00
\\ return @sizeOf(Foo);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:13: error: enums must have 1 or more fields " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-02 19:31:42 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" union with 0 fields " ,
2018-11-13 05:08:37 -08:00
\\const Foo = union {};
2018-01-25 01:10:11 -08:00
\\export fn entry() usize {
2017-12-03 21:56:27 -08:00
\\ return @sizeOf(Foo);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:13: error: unions must have 1 or more fields " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:56:27 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" enum value already taken " ,
2018-11-13 05:08:37 -08:00
\\const MultipleChoice = enum(u32) {
2017-12-02 19:31:42 -08:00
\\ A = 20,
\\ B = 40,
\\ C = 60,
\\ D = 1000,
\\ E = 60,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-02 19:31:42 -08:00
\\ var x = MultipleChoice.C;
\\}
,
2019-05-10 10:28:13 -07:00
" tmp.zig:6:5: error: enum tag value 60 already taken " ,
" tmp.zig:4:5: note: other occurrence here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 17:43:56 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" union with specified enum omits field " ,
2018-11-13 05:08:37 -08:00
\\const Letter = enum {
2017-12-03 17:43:56 -08:00
\\ A,
\\ B,
\\ C,
\\};
2018-11-13 05:08:37 -08:00
\\const Payload = union(Letter) {
2017-12-03 17:43:56 -08:00
\\ A: i32,
\\ B: f64,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() usize {
2017-12-03 17:43:56 -08:00
\\ return @sizeOf(Payload);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:17: error: enum field missing: 'C' " ,
" tmp.zig:4:5: note: declared here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:32:12 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" @TagType when union has no attached enum " ,
2018-11-13 05:08:37 -08:00
\\const Foo = union {
2017-12-03 21:32:12 -08:00
\\ A: i32,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-03 21:32:12 -08:00
\\ const x = @TagType(Foo);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:24: error: union 'Foo' has no tag " ,
" tmp.zig:1:13: note: consider 'union(enum)' here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:32:12 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" non-integer tag type to automatic union enum " ,
2018-11-13 05:08:37 -08:00
\\const Foo = union(enum(f32)) {
2017-12-03 21:32:12 -08:00
\\ A: i32,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-03 21:32:12 -08:00
\\ const x = @TagType(Foo);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:24: error: expected integer tag type, found 'f32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:32:12 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" non-enum tag type passed to union " ,
2018-11-13 05:08:37 -08:00
\\const Foo = union(u32) {
2017-12-03 21:32:12 -08:00
\\ A: i32,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-03 21:32:12 -08:00
\\ const x = @TagType(Foo);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:1:19: error: expected enum tag type, found 'u32' " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:32:12 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" union auto-enum value already taken " ,
2018-11-13 05:08:37 -08:00
\\const MultipleChoice = union(enum(u32)) {
2017-12-03 21:32:12 -08:00
\\ A = 20,
\\ B = 40,
\\ C = 60,
\\ D = 1000,
\\ E = 60,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ var x = MultipleChoice { .C = {} };
2017-12-03 21:32:12 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:9: error: enum tag value 60 already taken " ,
" tmp.zig:4:9: note: other occurrence here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:32:12 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" union enum field does not match enum " ,
2018-11-13 05:08:37 -08:00
\\const Letter = enum {
2017-12-03 21:56:27 -08:00
\\ A,
\\ B,
\\ C,
\\};
2018-11-13 05:08:37 -08:00
\\const Payload = union(Letter) {
2017-12-03 21:56:27 -08:00
\\ A: i32,
\\ B: f64,
\\ C: bool,
\\ D: bool,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ var a = Payload {.A = 1234};
2017-12-03 21:56:27 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:10:5: error: enum field not found: 'D' " ,
" tmp.zig:1:16: note: enum declared here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:56:27 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" field type supplied in an enum " ,
2018-11-13 05:08:37 -08:00
\\const Letter = enum {
2017-12-03 21:56:27 -08:00
\\ A: void,
\\ B,
\\ C,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-03 21:56:27 -08:00
\\ var b = Letter.B;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:8: error: structs and unions, not enums, support field types " ,
" tmp.zig:1:16: note: consider 'union(enum)' here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:56:27 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" struct field missing type " ,
2018-11-13 05:08:37 -08:00
\\const Letter = struct {
2017-12-03 21:56:27 -08:00
\\ A,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ var a = Letter { .A = {} };
2017-12-03 21:56:27 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: struct field missing type " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:56:27 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" extern union field missing type " ,
2018-11-13 05:08:37 -08:00
\\const Letter = extern union {
2017-12-03 21:56:27 -08:00
\\ A,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ var a = Letter { .A = {} };
2017-12-03 21:56:27 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:5: error: union field missing type " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:56:27 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" extern union given enum tag type " ,
2018-11-13 05:08:37 -08:00
\\const Letter = enum {
2017-12-03 21:56:27 -08:00
\\ A,
\\ B,
\\ C,
\\};
2018-11-13 05:08:37 -08:00
\\const Payload = extern union(Letter) {
2017-12-03 21:56:27 -08:00
\\ A: i32,
\\ B: f64,
\\ C: bool,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ var a = Payload { .A = 1234 };
2017-12-03 21:56:27 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:30: error: extern union does not support enum tag type " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:56:27 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" packed union given enum tag type " ,
2018-11-13 05:08:37 -08:00
\\const Letter = enum {
2017-12-03 21:56:27 -08:00
\\ A,
\\ B,
\\ C,
\\};
2018-11-13 05:08:37 -08:00
\\const Payload = packed union(Letter) {
2017-12-03 21:56:27 -08:00
\\ A: i32,
\\ B: f64,
\\ C: bool,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ var a = Payload { .A = 1234 };
2017-12-03 21:56:27 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:30: error: packed union does not support enum tag type " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-03 21:56:27 -08:00
2019-09-01 03:46:02 -07:00
cases . add (
" packed union with automatic layout field " ,
\\const Foo = struct {
\\ a: u32,
\\ b: f32,
\\};
\\const Payload = packed union {
\\ A: Foo,
\\ B: bool,
\\};
\\export fn entry() void {
\\ var a = Payload { .B = true };
\\}
,
" tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation " ,
) ;
2018-05-28 17:23:55 -07:00
cases . add (
" switch on union with no attached enum " ,
2018-11-13 05:08:37 -08:00
\\const Payload = union {
2017-12-03 21:56:27 -08:00
\\ A: i32,
\\ B: f64,
\\ C: bool,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-11-13 05:08:37 -08:00
\\ const a = Payload { .A = 1234 };
2017-12-03 21:56:27 -08:00
\\ foo(a);
\\}
2018-05-31 07:56:59 -07:00
\\fn foo(a: *const Payload) void {
2018-05-17 20:21:44 -07:00
\\ switch (a.*) {
2017-12-03 21:56:27 -08:00
\\ Payload.A => {},
\\ else => unreachable,
\\ }
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:11:14: error: switch on union which has no attached enum " ,
" tmp.zig:1:17: note: consider 'union(enum)' here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-05 15:09:22 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" enum in field count range but not matching tag " ,
2018-11-13 05:08:37 -08:00
\\const Foo = enum(u32) {
2017-12-05 15:09:22 -08:00
\\ A = 10,
\\ B = 11,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2018-06-19 00:50:38 -07:00
\\ var x = @intToEnum(Foo, 0);
2017-12-05 15:09:22 -08:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0 " ,
" tmp.zig:1:13: note: 'Foo' declared here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-05 17:46:58 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" comptime cast enum to union but field has payload " ,
2018-11-13 05:08:37 -08:00
\\const Letter = enum { A, B, C };
\\const Value = union(Letter) {
2017-12-05 17:46:58 -08:00
\\ A: i32,
\\ B,
\\ C,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-05 17:46:58 -08:00
\\ var x: Value = Letter.A;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A' " ,
" tmp.zig:3:5: note: field 'A' declared here " ,
2018-05-28 17:23:55 -07:00
) ;
2017-12-05 17:46:58 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
" runtime cast to union which has non-void fields " ,
2018-11-13 05:08:37 -08:00
\\const Letter = enum { A, B, C };
\\const Value = union(Letter) {
2017-12-05 17:46:58 -08:00
\\ A: i32,
\\ B,
\\ C,
\\};
2018-01-25 01:10:11 -08:00
\\export fn entry() void {
2017-12-05 17:46:58 -08:00
\\ foo(Letter.A);
\\}
2018-01-25 01:10:11 -08:00
\\fn foo(l: Letter) void {
2017-12-05 17:46:58 -08:00
\\ var x: Value = l;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields " ,
" tmp.zig:3:5: note: field 'A' has type 'i32' " ,
2018-05-28 17:23:55 -07:00
) ;
2018-02-27 15:51:22 -08:00
2018-05-28 17:23:55 -07:00
cases . add (
2018-09-07 14:43:01 -07:00
" taking byte offset of void field in struct " ,
2018-11-13 05:08:37 -08:00
\\const Empty = struct {
2018-03-13 22:07:40 -07:00
\\ val: void,
\\};
\\export fn foo() void {
2018-09-07 14:43:01 -07:00
\\ const fieldOffset = @byteOffsetOf(Empty, "val",);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:46: error: zero-bit field 'val' in struct 'Empty' has no offset " ,
2018-09-07 14:43:01 -07:00
) ;
cases . add (
" taking bit offset of void field in struct " ,
2018-11-13 05:08:37 -08:00
\\const Empty = struct {
2018-09-07 14:43:01 -07:00
\\ val: void,
\\};
\\export fn foo() void {
\\ const fieldOffset = @bitOffsetOf(Empty, "val",);
2018-03-13 22:07:40 -07:00
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset " ,
2018-05-28 17:23:55 -07:00
) ;
2018-05-01 03:00:39 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" invalid union field access in comptime " ,
2018-11-13 05:08:37 -08:00
\\const Foo = union {
2018-05-01 03:00:39 -07:00
\\ Bar: u8,
\\ Baz: void,
\\};
\\comptime {
2019-02-14 15:54:37 -08:00
\\ var foo = Foo {.Baz = {}};
2018-05-01 03:00:39 -07:00
\\ const bar_val = foo.Bar;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set " ,
2018-05-28 17:23:55 -07:00
) ;
2018-05-01 03:09:34 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" getting return type of generic function " ,
2018-04-28 08:17:48 -07:00
\\fn generic(a: var) void {}
\\comptime {
\\ _ = @typeOf(generic).ReturnType;
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic " ,
2018-05-28 17:23:55 -07:00
) ;
2018-04-28 08:17:48 -07:00
2018-05-28 17:23:55 -07:00
cases . add (
" getting @ArgType of generic function " ,
2018-04-28 08:17:48 -07:00
\\fn generic(a: var) void {}
\\comptime {
\\ _ = @ArgType(@typeOf(generic), 0);
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic " ,
2018-05-28 17:23:55 -07:00
) ;
2018-11-19 13:22:21 -08:00
cases . add (
" unsupported modifier at start of asm output constraint " ,
\\export fn foo() void {
\\ var bar: u32 = 3;
\\ asm volatile ("" : [baz]"+r"(bar) : : "");
\\}
,
2019-03-01 12:35:29 -08:00
" tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/215 " ,
2018-11-19 13:22:21 -08:00
) ;
cases . add (
" comptime_int in asm input " ,
\\export fn foo() void {
\\ asm volatile ("" : : [bar]"r"(3) : "");
\\}
2018-12-05 12:32:25 -08:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int " ,
2018-11-19 13:22:21 -08:00
) ;
cases . add (
" comptime_float in asm input " ,
\\export fn foo() void {
\\ asm volatile ("" : : [bar]"r"(3.17) : "");
\\}
2018-12-05 12:32:25 -08:00
,
2019-03-01 12:35:29 -08:00
" tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float " ,
2018-11-19 13:22:21 -08:00
) ;
2019-02-01 03:12:56 -08:00
cases . add (
" runtime assignment to comptime struct type " ,
\\const Foo = struct {
\\ Bar: u8,
\\ Baz: type,
\\};
\\export fn f() void {
\\ var x: u8 = 0;
\\ const foo = Foo { .Bar = x, .Baz = u8 };
\\}
,
2019-06-25 16:03:56 -07:00
" tmp.zig:7:23: error: unable to evaluate constant expression " ,
2019-02-01 03:12:56 -08:00
) ;
cases . add (
" runtime assignment to comptime union type " ,
\\const Foo = union {
\\ Bar: u8,
\\ Baz: type,
\\};
\\export fn f() void {
\\ var x: u8 = 0;
\\ const foo = Foo { .Bar = x };
\\}
,
2019-06-25 16:03:56 -07:00
" tmp.zig:7:23: error: unable to evaluate constant expression " ,
2019-02-01 03:12:56 -08:00
) ;
2019-02-13 03:19:08 -08:00
2019-06-29 09:32:26 -07:00
cases . addTest (
2019-09-18 12:41:56 -07:00
" @shuffle with selected index past first vector length " ,
2019-06-29 09:32:26 -07:00
\\export fn entry() void {
2019-09-18 12:41:56 -07:00
\\ const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 };
\\ const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 };
\\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
2019-06-29 09:32:26 -07:00
\\}
,
2019-09-18 12:41:56 -07:00
" tmp.zig:4:39: error: mask index '4' has out-of-bounds selection " ,
" tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32) " ,
" tmp.zig:4:30: note: selections from the second vector are specified with negative numbers " ,
2019-06-29 09:32:26 -07:00
) ;
2019-02-13 03:19:08 -08:00
cases . addTest (
" nested vectors " ,
\\export fn entry() void {
\\ const V = @Vector(4, @Vector(4, u8));
\\ var v: V = undefined;
\\}
,
2019-07-25 09:11:37 -07:00
" tmp.zig:2:26: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid " ,
2019-02-13 03:19:08 -08:00
) ;
2019-02-19 12:18:57 -08:00
2019-07-21 08:41:43 -07:00
cases . addTest (
" bad @splat type " ,
\\export fn entry() void {
\\ const c = 4;
\\ var v = @splat(4, c);
\\}
,
2019-09-19 07:48:04 -07:00
" tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid " ,
2019-07-21 08:41:43 -07:00
) ;
2019-02-20 05:04:46 -08:00
cases . add ( " compileLog of tagged enum doesn't crash the compiler " ,
2019-02-19 12:18:57 -08:00
\\const Bar = union(enum(u32)) {
\\ X: i32 = 1
\\};
\\
\\fn testCompileLog(x: Bar) void {
\\ @compileLog(x);
\\}
\\
\\pub fn main () void {
\\ comptime testCompileLog(Bar{.X = 123});
\\}
2019-03-01 12:35:29 -08:00
, " tmp.zig:6:5: error: found compile log statement " ) ;
2019-03-31 12:19:13 -07:00
cases . add (
" attempted implicit cast from *const T to *[1]T " ,
\\export fn entry(byte: u8) void {
\\ const w: i32 = 1234;
\\ var x: *const i32 = &w;
\\ var y: *[1]i32 = x;
\\ y[0] += 1;
\\}
,
" tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32' " ,
2019-11-20 13:08:01 -08:00
" tmp.zig:4:22: note: cast discards const qualifier " ,
2019-03-31 12:19:13 -07:00
) ;
cases . add (
" attempted implicit cast from *const T to []T " ,
\\export fn entry() void {
\\ const u: u32 = 42;
\\ const x: []u32 = &u;
\\}
,
" tmp.zig:3:23: error: expected type '[]u32', found '*const u32' " ,
) ;
2019-05-10 02:23:26 -07:00
cases . add (
" for loop body expression ignored " ,
\\fn returns() usize {
\\ return 2;
\\}
\\export fn f1() void {
\\ for ("hello") |_| returns();
\\}
\\export fn f2() void {
\\ var x: anyerror!i32 = error.Bad;
\\ for ("hello") |_| returns() else unreachable;
\\}
,
" tmp.zig:5:30: error: expression value is ignored " ,
" tmp.zig:9:30: error: expression value is ignored " ,
) ;
2019-09-03 13:29:04 -07:00
cases . add (
" aligned variable of zero-bit type " ,
\\export fn f() void {
\\ var s: struct {} align(4) = undefined;
\\}
,
" tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned " ,
) ;
2019-09-07 04:22:33 -07:00
cases . add (
" function returning opaque type " ,
\\const FooType = @OpaqueType();
\\export fn bar() !FooType {
\\ return error.InvalidValue;
\\}
,
" tmp.zig:2:18: error: opaque return type 'FooType' not allowed " ,
" tmp.zig:1:1: note: declared here " ,
) ;
2019-10-09 11:46:12 -07:00
2019-11-08 12:56:21 -08:00
cases . add ( // fixed bug #2032
2019-10-09 11:46:12 -07:00
" compile diagnostic string for top level decl type " ,
\\export fn entry() void {
\\ var foo: u32 = @This(){};
\\}
,
" tmp.zig:2:27: error: expected type 'u32', found '(root)' " ,
" tmp.zig:1:1: note: (root) declared here " ,
) ;
2017-04-19 01:12:22 -07:00
}