test: fix incorrect default target spec; port all incremental tests

This commit is contained in:
Jakub Konka 2022-04-27 15:37:54 +02:00
parent 133708d939
commit 97b781955e
102 changed files with 1360 additions and 1 deletions

View File

@ -178,7 +178,7 @@ const TestManifestConfigDefaults = struct {
// getting more and more complete
// Linux
inline for (&[_][]const u8{ "x86_64", "arm", "aarch64" }) |arch| {
defaults = defaults ++ arch ++ "-linux-" ++ ",";
defaults = defaults ++ arch ++ "-linux" ++ ",";
}
// macOS
inline for (&[_][]const u8{ "x86_64", "aarch64" }) |arch| {

View File

@ -0,0 +1,17 @@
var array = [_]usize{ 0, 42, 123, 34 };
var slice: []const usize = &array;
pub fn main() void {
assert(slice[0] == 0);
assert(slice[1] == 42);
assert(slice[2] == 123);
assert(slice[3] == 34);
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
// target=x86_64-linux,x86_64-macos
//

View File

@ -0,0 +1,13 @@
const T = struct {
const T = struct {
fn f() void {
_ = T;
}
};
};
// error
//
// :4:17: error: ambiguous reference
// :2:5: note: declared here
// :1:1: note: also declared here

View File

@ -0,0 +1,9 @@
pub fn main() void {
var x = null;
_ = x;
}
// error
// output_mode=Exe
//
// :2:9: error: variable of type '@TypeOf(null)' must be const or comptime

View File

@ -0,0 +1,9 @@
pub fn main() void {
while (true) {
break;
}
}
// run
// target=x86_64-linux,x86_64-macos,aarch64-linux,aarch64-macos
//

View File

@ -0,0 +1,8 @@
pub fn main() void {
foo: while (true) {
break :foo;
}
}
// run
//

View File

@ -0,0 +1,10 @@
pub fn main() void {
var i: u64 = 0;
while (true) : (i += 1) {
if (i == 4) return;
continue;
}
}
// run
//

View File

@ -0,0 +1,10 @@
pub fn main() void {
var i: u64 = 0;
foo: while (true) : (i += 1) {
if (i == 4) return;
continue :foo;
}
}
// run
//

View File

@ -0,0 +1,11 @@
pub fn main() void {
const i: anyerror!u64 = 0;
const caught = i catch 5;
assert(caught == 0);
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -0,0 +1,11 @@
pub fn main() void {
const i: anyerror!u64 = error.B;
const caught = i catch 5;
assert(caught == 5);
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -0,0 +1,11 @@
pub fn main() void {
const a: anyerror!comptime_int = 42;
const b: *const comptime_int = &(a catch unreachable);
assert(b.* == 42);
}
fn assert(b: bool) void {
if (!b) unreachable; // assertion failure
}
// run
//

View File

@ -0,0 +1,10 @@
pub fn main() void {
const a: anyerror!u32 = error.B;
_ = &(a catch |err| assert(err == error.B));
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -0,0 +1,10 @@
pub fn main() void {
const a: anyerror!u32 = error.Bar;
a catch |err| assert(err == error.Bar);
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -0,0 +1,7 @@
export fn foo() void {
@compileError("this is an error");
}
// error
//
// :2:5: error: this is an error

View File

@ -0,0 +1,16 @@
pub fn main() void {
var x: usize = 3;
const y = add(10, 2, x);
if (y - 6 != 0) unreachable;
}
inline fn add(a: usize, b: usize, c: usize) usize {
if (a == 10) @compileError("bad");
return a + b + c;
}
// error
// output_mode=Exe
//
// :8:18: error: bad
// :3:18: note: called from here

View File

@ -0,0 +1,13 @@
pub fn main() void {
var x: usize = 3;
const y = add(1, 2, x);
if (y - 6 != 0) unreachable;
}
inline fn add(a: usize, b: usize, c: usize) usize {
if (a == 10) @compileError("bad");
return a + b + c;
}
// run
//

View File

@ -0,0 +1,17 @@
export fn _start() noreturn {
const b = true;
var f: u32 = 1;
@compileLog(b, 20, f, x);
@compileLog(1000);
var bruh: usize = true;
_ = bruh;
unreachable;
}
export fn other() void {
@compileLog(1234);
}
fn x() void {}
// error
//
// :6:23: error: expected usize, found bool

View File

@ -0,0 +1,16 @@
export fn _start() noreturn {
const b = true;
var f: u32 = 1;
@compileLog(b, 20, f, x);
@compileLog(1000);
unreachable;
}
export fn other() void {
@compileLog(1234);
}
fn x() void {}
// error
//
// :9:5: error: found compile log statement
// :4:5: note: also here

View File

@ -0,0 +1,12 @@
pub fn main() void {
var a: u32 = 0;
comptime var b: u32 = 0;
if (a == 0) b = 3;
}
// error
// output_mode=Exe
// target=x86_64-linux,x86_64-macos
//
// :4:21: error: store to comptime variable depends on runtime condition
// :4:11: note: runtime condition here

View File

@ -0,0 +1,13 @@
pub fn main() void {
var a: u32 = 0;
comptime var b: u32 = 0;
switch (a) {
0 => {},
else => b = 3,
}
}
// error
//
// :6:21: error: store to comptime variable depends on runtime condition
// :4:13: note: runtime condition here

View File

@ -0,0 +1,34 @@
const builtin = @import("builtin");
extern "c" fn write(usize, usize, usize) usize;
pub fn main() void {
comptime var len: u32 = 5;
print(len);
len += 9;
print(len);
}
fn print(len: usize) void {
switch (builtin.os.tag) {
.linux => {
asm volatile ("syscall"
:
: [number] "{rax}" (1),
[arg1] "{rdi}" (1),
[arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
[arg3] "{rdx}" (len),
: "rcx", "r11", "memory"
);
},
.macos => {
_ = write(1, @ptrToInt("Hello, World!\n"), len);
},
else => unreachable,
}
}
// run
//
// HelloHello, World!
//

View File

@ -0,0 +1,10 @@
comptime {
var x: i32 = 1;
x += 1;
if (x != 1) unreachable;
}
pub fn main() void {}
// error
//
// :4:17: error: unable to resolve comptime value

View File

@ -0,0 +1,9 @@
pub fn main() void {
comptime var i: u64 = 0;
while (i < 5) : (i += 1) {}
}
// error
//
// :3:24: error: cannot store to comptime variable in non-inline loop
// :3:5: note: non-inline loop here

View File

@ -0,0 +1,15 @@
pub fn main() void {
var a: u32 = 0;
if (a == 0) {
comptime var b: u32 = 0;
b = 1;
}
}
comptime {
var x: i32 = 1;
x += 1;
if (x != 2) unreachable;
}
// run
//

View File

@ -0,0 +1,32 @@
const builtin = @import("builtin");
extern "c" fn write(usize, usize, usize) usize;
pub fn main() void {
comptime var i: u64 = 2;
inline while (i < 6) : (i += 1) {
print(i);
}
}
fn print(len: usize) void {
switch (builtin.os.tag) {
.linux => {
asm volatile ("syscall"
:
: [number] "{rax}" (1),
[arg1] "{rdi}" (1),
[arg2] "{rsi}" (@ptrToInt("Hello")),
[arg3] "{rdx}" (len),
: "rcx", "r11", "memory"
);
},
.macos => {
_ = write(1, @ptrToInt("Hello"), len);
},
else => unreachable,
}
}
// run
//
// HeHelHellHello

View File

@ -0,0 +1,6 @@
pub const a = if (true && false) 1 else 2;
// error
// output_mode=Exe
//
// :1:24: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND

View File

@ -0,0 +1,11 @@
pub fn main() void {
const a = true;
const b = false;
_ = a & &b;
}
// error
//
// :4:11: error: incompatible types: 'bool' and '*const bool'
// :4:9: note: type 'bool' here
// :4:13: note: type '*const bool' here

View File

@ -0,0 +1,7 @@
pub fn main() void {
const b: u8 = 1;
_ = &&b;
}
// run
//

View File

@ -0,0 +1,9 @@
comptime {
const x = foo + foo;
_ = x;
}
extern var foo: i32;
// error
//
// :2:15: error: unable to resolve comptime value

View File

@ -0,0 +1,8 @@
export fn entry() void {
_ = foo;
}
extern var foo;
// error
//
// :4:8: error: unable to infer variable type

View File

@ -0,0 +1,14 @@
// dummy comment
fn entry() void {}
fn entry() void {}
fn foo() void {
var foo = 1234;
}
// error
//
// :3:1: error: redeclaration of 'entry'
// :2:1: note: other declaration here
// :6:9: error: local shadows declaration of 'foo'
// :5:1: note: declared here

View File

@ -0,0 +1,8 @@
// dummy comment
var foo = false;
var foo = true;
// error
//
// :3:1: error: redeclaration of 'foo'
// :2:1: note: other declaration here

View File

@ -0,0 +1,5 @@
// error
// output_mode=Exe
// target=x86_64-linux
//
// :109:9: error: struct 'tmp.tmp' has no member named 'main'

View File

@ -0,0 +1,5 @@
pub export fn _start() noreturn {}
// error
//
// :1:34: error: expected noreturn, found void

View File

@ -0,0 +1,32 @@
pub export fn _start() noreturn {
print();
exit();
}
fn print() void {
asm volatile ("syscall"
:
: [number] "{rax}" (1),
[arg1] "{rdi}" (1),
[arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
[arg3] "{rdx}" (14),
: "rcx", "r11", "memory"
);
return;
}
fn exit() noreturn {
asm volatile ("syscall"
:
: [number] "{rax}" (231),
[arg1] "{rdi}" (0),
: "rcx", "r11", "memory"
);
unreachable;
}
// run
//
// Hello, World!
//

View File

@ -0,0 +1,20 @@
pub fn main() void {
print();
}
fn print() void {
asm volatile ("syscall"
:
: [number] "{rax}" (1),
[arg1] "{rdi}" (1),
[arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
[arg3] "{rdx}" (14),
: "rcx", "r11", "memory"
);
return;
}
// run
//
// Hello, World!
//

View File

@ -0,0 +1,20 @@
pub fn main() void {
print();
}
fn print() void {
asm volatile ("syscall"
:
: [number] "{rax}" (1),
[arg1] "{rdi}" (1),
[arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")),
[arg3] "{rdx}" (104),
: "rcx", "r11", "memory"
);
return;
}
// run
//
// What is up? This is a longer message that will force the data to be relocated in virtual address space.
//

View File

@ -0,0 +1,22 @@
pub fn main() void {
print();
print();
}
fn print() void {
asm volatile ("syscall"
:
: [number] "{rax}" (1),
[arg1] "{rdi}" (1),
[arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")),
[arg3] "{rdx}" (104),
: "rcx", "r11", "memory"
);
return;
}
// run
//
// What is up? This is a longer message that will force the data to be relocated in virtual address space.
// What is up? This is a longer message that will force the data to be relocated in virtual address space.
//

View File

@ -0,0 +1,5 @@
// error
// output_mode=Exe
// target=x86_64-macos
//
// :109:9: error: struct 'tmp.tmp' has no member named 'main'

View File

@ -0,0 +1,5 @@
pub export fn main() noreturn {}
// error
//
// :1:32: error: expected noreturn, found void

View File

@ -0,0 +1,19 @@
extern "c" fn write(usize, usize, usize) usize;
extern "c" fn exit(usize) noreturn;
pub export fn main() noreturn {
print();
exit(0);
}
fn print() void {
const msg = @ptrToInt("Hello, World!\n");
const len = 14;
_ = write(1, msg, len);
}
// run
//
// Hello, World!
//

View File

@ -0,0 +1,16 @@
extern "c" fn write(usize, usize, usize) usize;
pub fn main() void {
print();
}
fn print() void {
const msg = @ptrToInt("Hello, World!\n");
const len = 14;
_ = write(1, msg, len);
}
// run
//
// Hello, World!
//

View File

@ -0,0 +1,22 @@
extern "c" fn write(usize, usize, usize) usize;
pub fn main() void {
print();
print();
print();
print();
}
fn print() void {
const msg = @ptrToInt("Hello, World!\n");
const len = 14;
_ = write(1, msg, len);
}
// run
//
// Hello, World!
// Hello, World!
// Hello, World!
// Hello, World!
//

View File

@ -0,0 +1,16 @@
extern "c" fn write(usize, usize, usize) usize;
pub fn main() void {
print();
}
fn print() void {
const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
const len = 104;
_ = write(1, msg, len);
}
// run
//
// What is up? This is a longer message that will force the data to be relocated in virtual address space.
//

View File

@ -0,0 +1,18 @@
extern "c" fn write(usize, usize, usize) usize;
pub fn main() void {
print();
print();
}
fn print() void {
const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
const len = 104;
_ = write(1, msg, len);
}
// run
//
// What is up? This is a longer message that will force the data to be relocated in virtual address space.
// What is up? This is a longer message that will force the data to be relocated in virtual address space.
//

View File

@ -0,0 +1,16 @@
pub fn main() void {
const number = 1234;
const x = asm volatile ("syscall"
: [o] "{rax}" (-> number),
: [number] "{rax}" (231),
[arg1] "{rdi}" (60),
: "rcx", "r11", "memory"
);
_ = x;
}
// error
// output_mode=Exe
// target=x86_64-linux
//
// :4:27: error: expected type, found comptime_int

View File

@ -0,0 +1,15 @@
const S = struct {
comptime {
asm volatile (
\\zig_moment:
\\syscall
);
}
};
pub fn main() void {
_ = S;
}
// error
//
// :3:13: error: volatile is meaningless on global assembly

View File

@ -0,0 +1,12 @@
pub fn main() void {
var bruh: u32 = 1;
asm (""
:
: [bruh] "{rax}" (4)
: "memory"
);
}
// error
//
// :3:5: error: assembly expression with no output must be marked volatile

View File

@ -0,0 +1,12 @@
pub fn main() void {}
comptime {
asm (""
:
: [bruh] "{rax}" (4)
: "memory"
);
}
// error
//
// :3:5: error: global assembly cannot have inputs, outputs, or clobbers

View File

@ -0,0 +1,15 @@
pub fn f() void {
var bar: bool = true;
const S = struct {
fn baz() bool {
return bar;
}
};
_ = S;
}
// error
//
// :5:20: error: mutable 'bar' not accessible from here
// :2:9: note: declared mutable here
// :3:15: note: crosses namespace boundary here

View File

@ -0,0 +1,8 @@
pub fn main() void {
_ = @intToPtr(*u8, 0);
}
// error
// output_mode=Exe
//
// :2:24: error: pointer type '*u8' does not allow address zero

View File

@ -0,0 +1,7 @@
pub fn main() void {
_ = @intToPtr(*u32, 2);
}
// error
//
// :2:25: error: pointer type '*u32' requires aligned address

View File

@ -0,0 +1,31 @@
pub fn main() void {
const fd = open();
_ = write(fd, "a", 1);
_ = close(fd);
}
fn open() usize {
return 42;
}
fn write(fd: usize, a: [*]const u8, len: usize) usize {
return syscall4(.WRITE, fd, @ptrToInt(a), len);
}
fn syscall4(n: enum { WRITE }, a: usize, b: usize, c: usize) usize {
_ = n;
_ = a;
_ = b;
_ = c;
return 23;
}
fn close(fd: usize) usize {
if (fd != 42)
unreachable;
return 0;
}
// run
// target=x86_64-linux
//

View File

@ -0,0 +1,18 @@
pub fn main() void {
var x: usize = 1;
var y: bool = getFalse();
_ = y;
assert(x == 1);
}
fn getFalse() bool {
return false;
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
//

View File

@ -0,0 +1,16 @@
pub fn main() void {
var x: u32 = undefined;
set(&x);
assert(x == 123);
}
fn set(x: *u32) void {
x.* = 123;
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
//

View File

@ -0,0 +1,16 @@
pub fn main() void {
var x: u16 = undefined;
set(&x);
assert(x == 123);
}
fn set(x: *u16) void {
x.* = 123;
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
//

View File

@ -0,0 +1,16 @@
pub fn main() void {
var x: u8 = undefined;
set(&x);
assert(x == 123);
}
fn set(x: *u8) void {
x.* = 123;
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
//

View File

@ -0,0 +1,25 @@
const Foo = struct {
a: u8,
b: u32,
fn first(self: *Foo) u8 {
return self.a;
}
fn second(self: *Foo) u32 {
return self.b;
}
};
pub fn main() void {
var foo = Foo{ .a = 1, .b = 5 };
assert(foo.first() == 1);
assert(foo.second() == 5);
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
//

View File

@ -0,0 +1,35 @@
const Foo = struct {
a: u8,
b: u32,
fn first(self: *Foo) u8 {
return self.a;
}
fn second(self: *Foo) u32 {
return self.b;
}
};
pub fn main() void {
var foo = Foo{ .a = 1, .b = 5 };
assert(foo.first() == 1);
assert(foo.second() == 5);
foo.a = 10;
foo.b = 255;
assert(foo.first() == 10);
assert(foo.second() == 255);
var foo2 = Foo{ .a = 15, .b = 255 };
assert(foo2.first() == 15);
assert(foo2.second() == 255);
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
//

View File

@ -0,0 +1,25 @@
const Foo = struct {
a: u8,
b: u32,
fn first(self: *Foo) u8 {
return self.a;
}
fn second(self: *Foo) u32 {
return self.b;
}
};
pub fn main() void {
var foo2 = Foo{ .a = 15, .b = 255 };
assert(foo2.first() == 15);
assert(foo2.second() == 255);
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
//

View File

@ -0,0 +1,18 @@
pub fn main() void {
const E = error{ A, B, D } || error{ A, B, C };
E.A catch {};
E.B catch {};
E.C catch {};
E.D catch {};
const E2 = error{ X, Y } || @TypeOf(error.Z);
E2.X catch {};
E2.Y catch {};
E2.Z catch {};
assert(anyerror || error{Z} == anyerror);
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -0,0 +1,9 @@
pub fn main() void {
const z = true || false;
_ = z;
}
// error
//
// :2:15: error: expected error set type, found 'bool'
// :2:20: note: '||' merges error sets; 'or' performs boolean OR

View File

@ -0,0 +1,13 @@
pub export fn _start() noreturn {
asm volatile ("syscall"
:
: [number] "{rax}" (60), // exit
[arg1] "{rdi}" (0),
: "rcx", "r11", "memory"
);
unreachable;
}
// run
// target=x86_64-linux
//

View File

@ -0,0 +1,12 @@
pub export fn _start() noreturn {
asm volatile ("syscall"
:
: [number] "{rax}" (231), // exit_group
[arg1] "{rdi}" (0),
: "rcx", "r11", "memory"
);
unreachable;
}
// run
//

View File

@ -0,0 +1,19 @@
pub fn main() void {
var x: u32 = undefined;
const maybe_x = byPtr(&x);
assert(maybe_x != null);
maybe_x.?.* = 123;
assert(x == 123);
}
fn byPtr(x: *u32) ?*u32 {
return x;
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
// target=x86_64-linux,x86_64-macos
//

View File

@ -0,0 +1,17 @@
pub fn main() void {
var x: u32 = undefined;
const maybe_x = byPtr(&x);
assert(maybe_x == null);
}
fn byPtr(x: *u32) ?*u32 {
_ = x;
return null;
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
//

View File

@ -0,0 +1,18 @@
pub fn main() void {
var x: u8 = undefined;
const maybe_x = byPtr(&x);
assert(maybe_x != null);
maybe_x.?.* = 255;
assert(x == 255);
}
fn byPtr(x: *u8) ?*u8 {
return x;
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
//

View File

@ -0,0 +1,18 @@
pub fn main() void {
var x: i8 = undefined;
const maybe_x = byPtr(&x);
assert(maybe_x != null);
maybe_x.?.* = -1;
assert(x == -1);
}
fn byPtr(x: *i8) ?*i8 {
return x;
}
fn assert(ok: bool) void {
if (!ok) unreachable;
}
// run
//

View File

@ -0,0 +1,11 @@
pub fn main() void {
const i: ?u64 = 0;
const result = i orelse 5;
assert(result == 0);
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -0,0 +1,11 @@
pub fn main() void {
const i: ?u64 = null;
const result = i orelse 5;
assert(result == 5);
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -0,0 +1,9 @@
pub fn main() void {
doNothing(0);
}
fn doNothing(arg: u0) void {
_ = arg;
}
// run
//

View File

@ -0,0 +1,12 @@
pub fn main() void {
const y = fibonacci(7);
if (y - 21 != 0) unreachable;
}
inline fn fibonacci(n: usize) usize {
if (n <= 2) return n;
return fibonacci(n - 2) + fibonacci(n - 1);
}
// run
//

View File

@ -0,0 +1,16 @@
// This additionally tests that the compile error reports the correct source location.
// Without storing source locations relative to the owner decl, the compile error
// here would be off by 2 bytes (from the "7" -> "999").
pub fn main() void {
const y = fibonacci(999);
if (y - 21 != 0) unreachable;
}
inline fn fibonacci(n: usize) usize {
if (n <= 2) return n;
return fibonacci(n - 2) + fibonacci(n - 1);
}
// error
//
// :11:21: error: evaluation exceeded 1000 backwards branches

View File

@ -0,0 +1,7 @@
pub fn main() void {
var a: comptime u32 = 0;
}
// error
//
// :2:12: error: redundant comptime keyword in already comptime scope

View File

@ -0,0 +1,9 @@
pub fn main() void {
comptime {
var a: u32 = comptime 0;
}
}
// error
//
// :3:22: error: redundant comptime keyword in already comptime scope

View File

@ -0,0 +1,16 @@
pub fn main() !void {
try a();
try b();
}
pub fn a() !void {
defer try b();
}
pub fn b() !void {
defer return a();
}
// error
//
// :7:11: error: 'try' not allowed inside defer expression
// :10:11: error: cannot return from defer expression

View File

@ -0,0 +1,16 @@
pub fn main() void {
var i: u32 = 10;
var j: u32 = 11;
assert(i & 1 == 0);
assert(j & 1 == 1);
var m1: u32 = 0b1111;
var m2: u32 = 0b0000;
assert(m1 & 0b1010 == 0b1010);
assert(m2 & 0b1010 == 0b0000);
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -0,0 +1,16 @@
pub fn main() void {
var i: u32 = 10;
var j: u32 = 11;
assert(i | 1 == 11);
assert(j | 1 == 11);
var m1: u32 = 0b1111;
var m2: u32 = 0b0000;
assert(m1 | 0b1010 == 0b1111);
assert(m2 | 0b1010 == 0b1010);
}
fn assert(b: bool) void {
if (!b) unreachable;
}
// run
//

View File

@ -0,0 +1,16 @@
pub fn main() void {
assert(callMe(2) == 24);
}
fn callMe(a: u8) u8 {
var b: u8 = a + 10;
const c = 2 * b;
return c;
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -0,0 +1,16 @@
pub fn main() void {
assert(callMe(2) == 24);
}
fn callMe(a: u16) u16 {
var b: u16 = a + 10;
const c = 2 * b;
return c;
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -0,0 +1,16 @@
pub fn main() void {
assert(callMe(2) == 24);
}
fn callMe(a: u32) u32 {
var b: u32 = a + 10;
const c = 2 * b;
return c;
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -0,0 +1,8 @@
export fn entry() i32 {
var foo: i32 addrspace(".general") = 1234;
return foo;
}
// error
//
// :2:28: error: cannot set address space of local variable 'foo'

View File

@ -0,0 +1,13 @@
test "@unionInit on union w/ tag but no fields" {
const S = struct {
comptime {
try expect(false);
}
};
_ = S;
}
// error
// is_test=1
//
// :4:13: error: 'try' outside function scope

View File

@ -0,0 +1,13 @@
pub fn main() void {
var x: usize = 0;
_ = x;
const z = @TypeOf(x, @as(u128, 5));
assert(z == u128);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -0,0 +1,11 @@
pub fn main() void {
const z = @TypeOf(true);
assert(z == bool);
}
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
// run
//

View File

@ -0,0 +1,9 @@
pub fn main() void {
_ = @TypeOf(true, 1);
}
// error
//
// :2:9: error: incompatible types: 'bool' and 'comptime_int'
// :2:17: note: type 'bool' here
// :2:23: note: type 'comptime_int' here

View File

@ -0,0 +1,8 @@
comptime {
foo: {}
}
// error
// output_mode=Exe
//
// :2:5: error: unused block label

View File

@ -0,0 +1,7 @@
comptime {
foo: while (true) {}
}
// error
//
// :2:5: error: unused while loop label

View File

@ -0,0 +1,7 @@
comptime {
foo: for ("foo") |_| {}
}
// error
//
// :2:5: error: unused for loop label

View File

@ -0,0 +1,8 @@
comptime {
blk: {blk: {}}
}
// error
//
// :2:11: error: redefinition of label 'blk'
// :2:5: note: previous definition here

View File

@ -0,0 +1,10 @@
pub fn main() void {
maybeErr() catch unreachable;
}
fn maybeErr() !void {
return;
}
// run
//

View File

@ -0,0 +1,11 @@
pub fn main() void {
maybeErr() catch return;
unreachable;
}
fn maybeErr() !void {
return error.NoWay;
}
// run
//

View File

@ -0,0 +1,9 @@
pub fn main() void {
var i: u32 = 10;
var i: u32 = 10;
}
// error
//
// :3:9: error: redeclaration of local variable 'i'
// :2:9: note: previous declaration here

View File

@ -0,0 +1,9 @@
var testing: i64 = 10;
pub fn main() void {
var testing: i64 = 20;
}
// error
//
// :3:9: error: local shadows declaration of 'testing'
// :1:1: note: declared here

View File

@ -0,0 +1,13 @@
fn a() type {
return struct {
pub fn b() void {
const c = 6;
const c = 69;
}
};
}
// error
//
// :5:19: error: redeclaration of local constant 'c'
// :4:19: note: previous declaration here

View File

@ -0,0 +1,10 @@
pub fn main() void {
var i = 0;
for ("n") |_, i| {
}
}
// error
//
// :3:19: error: redeclaration of local variable 'i'
// :2:9: note: previous declaration here

View File

@ -0,0 +1,10 @@
pub fn main() void {
var i = 0;
for ("n") |i| {
}
}
// error
//
// :3:16: error: redeclaration of local variable 'i'
// :2:9: note: previous declaration here

View File

@ -0,0 +1,10 @@
pub fn main() void {
var i = 0;
while ("n") |i| {
}
}
// error
//
// :3:18: error: redeclaration of local variable 'i'
// :2:9: note: previous declaration here

View File

@ -0,0 +1,13 @@
pub fn main() void {
var i = 0;
while ("n") |bruh| {
_ = bruh;
} else |i| {
}
}
// error
//
// :5:13: error: redeclaration of local variable 'i'
// :2:9: note: previous declaration here

View File

@ -0,0 +1,9 @@
pub fn main() void {
var i = 0;
if (true) |i| {}
}
// error
//
// :3:16: error: redeclaration of local variable 'i'
// :2:9: note: previous declaration here

Some files were not shown because too many files have changed in this diff Show More