authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-25 17:06:19-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-25 17:08:18-07:00
log50854226a6c6b78b4456ee6beeaae52ca0db6b0d
tree6a2ce0dfe300e82f54a592f5dc8f952d0f36ab32
parentfb85d3a0a2fd0774f78a38bbb63ac4ceb537d3ee

syntax: back to -> for return type, no more =>


14 files changed, 180 insertions(+), 180 deletions(-)

doc/langref.md+2-2
...@@ -23,7 +23,7 @@ RootExportDecl : many(Directive) "export" "Symbol" "String" ";"...@@ -23,7 +23,7 @@ RootExportDecl : many(Directive) "export" "Symbol" "String" ";"
2323
24ExternBlock : many(Directive) "extern" "{" many(FnDecl) "}"24ExternBlock : many(Directive) "extern" "{" many(FnDecl) "}"
2525
26FnProto : many(Directive) option(FnVisibleMod) "fn" "Symbol" ParamDeclList option(PrefixOpExpression)26FnProto : many(Directive) option(FnVisibleMod) "fn" "Symbol" ParamDeclList option("->" PrefixOpExpression)
2727
28Directive : "#" "Symbol" "(" "String" ")"28Directive : "#" "Symbol" "(" "String" ")"
2929
...@@ -31,7 +31,7 @@ FnVisibleMod : "pub" | "export"...@@ -31,7 +31,7 @@ FnVisibleMod : "pub" | "export"
3131
32FnDecl : FnProto ";"32FnDecl : FnProto ";"
3333
34FnDef : FnProto "=>" Block34FnDef : FnProto Block
3535
36ParamDeclList : "(" list(ParamDecl, ",") ")"36ParamDeclList : "(" list(ParamDecl, ",") ")"
3737
example/guess_number/main.zig+1-1
...@@ -3,7 +3,7 @@ export executable "guess_number";...@@ -3,7 +3,7 @@ export executable "guess_number";
3import "std.zig";3import "std.zig";
4import "rand.zig";4import "rand.zig";
55
6pub fn main(args: [][]u8) %void => {6pub fn main(args: [][]u8) -> %void {
7 %%stderr.print_str("Welcome to the Guess Number Game in Zig.\n");7 %%stderr.print_str("Welcome to the Guess Number Game in Zig.\n");
88
9 var seed : u32;9 var seed : u32;
example/hello_world/hello.zig+1-1
...@@ -2,6 +2,6 @@ export executable "hello";...@@ -2,6 +2,6 @@ export executable "hello";
22
3import "std.zig";3import "std.zig";
44
5pub fn main(args: [][]u8) %void => {5pub fn main(args: [][]u8) -> %void {
6 stdout.printf("Hello, world!\n");6 stdout.printf("Hello, world!\n");
7}7}
example/hello_world/hello_libc.zig+2-2
...@@ -2,10 +2,10 @@ export executable "hello";...@@ -2,10 +2,10 @@ export executable "hello";
22
3#link("c")3#link("c")
4extern {4extern {
5 fn printf(__format: &const u8, ...) i32;5 fn printf(__format: &const u8, ...) -> i32;
6}6}
77
8export fn main(argc: i32, argv: &&u8) i32 => {8export fn main(argc: i32, argv: &&u8) -> i32 {
9 printf(c"Hello, world!\n");9 printf(c"Hello, world!\n");
10 return 0;10 return 0;
11}11}
example/multiple_files/foo.zig+2-2
...@@ -2,10 +2,10 @@ import "std.zig";...@@ -2,10 +2,10 @@ import "std.zig";
22
3// purposefully conflicting function with main.zig3// purposefully conflicting function with main.zig
4// but it's private so it should be OK4// but it's private so it should be OK
5fn private_function() => {5fn private_function() {
6 stdout.printf("OK 1\n");6 stdout.printf("OK 1\n");
7}7}
88
9pub fn print_text() => {9pub fn print_text() {
10 private_function();10 private_function();
11}11}
example/multiple_files/main.zig+2-3
...@@ -3,12 +3,11 @@ export executable "test-multiple-files";...@@ -3,12 +3,11 @@ export executable "test-multiple-files";
3import "std.zig";3import "std.zig";
4import "foo.zig";4import "foo.zig";
55
6pub fn main(args: [][]u8) i32 => {6pub fn main(args: [][]u8) -> %void {
7 private_function();7 private_function();
8 stdout.printf("OK 2\n");8 stdout.printf("OK 2\n");
9 return 0;
10}9}
1110
12fn private_function() => {11fn private_function() {
13 print_text();12 print_text();
14}13}
example/shared_library/mathtest.zig+2-2
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1#version("2.0.0")1#version("2.0.0")
2export library "mathtest";2export library "mathtest";
33
4export fn add(a: i32, b: i32) i32 => {4export fn add(a: i32, b: i32) -> i32 {
5 a + b5 a + b
6}6}
77
8export fn hang() unreachable => {8export fn hang() -> unreachable {
9 while (true) { }9 while (true) { }
10}10}
src/parser.cpp+6-5
...@@ -2675,7 +2675,7 @@ static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandato...@@ -2675,7 +2675,7 @@ static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandato
2675}2675}
26762676
2677/*2677/*
2678FnProto : many(Directive) option(FnVisibleMod) "fn" "Symbol" ParamDeclList option(PrefixOpExpression)2678FnProto : many(Directive) option(FnVisibleMod) "fn" "Symbol" ParamDeclList option("->" PrefixOpExpression)
2679*/2679*/
2680static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mandatory) {2680static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mandatory) {
2681 Token *first_token = &pc->tokens->at(*token_index);2681 Token *first_token = &pc->tokens->at(*token_index);
...@@ -2727,8 +2727,10 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand...@@ -2727,8 +2727,10 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand
2727 ast_parse_param_decl_list(pc, token_index, &node->data.fn_proto.params, &node->data.fn_proto.is_var_args);2727 ast_parse_param_decl_list(pc, token_index, &node->data.fn_proto.params, &node->data.fn_proto.is_var_args);
27282728
2729 Token *next_token = &pc->tokens->at(*token_index);2729 Token *next_token = &pc->tokens->at(*token_index);
2730 node->data.fn_proto.return_type = ast_parse_prefix_op_expr(pc, token_index, false);2730 if (next_token->id == TokenIdArrow) {
2731 if (!node->data.fn_proto.return_type) {2731 *token_index += 1;
2732 node->data.fn_proto.return_type = ast_parse_prefix_op_expr(pc, token_index, false);
2733 } else {
2732 node->data.fn_proto.return_type = ast_create_void_type_node(pc, next_token);2734 node->data.fn_proto.return_type = ast_create_void_type_node(pc, next_token);
2733 }2735 }
27342736
...@@ -2737,7 +2739,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand...@@ -2737,7 +2739,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand
2737}2739}
27382740
2739/*2741/*
2740FnDef : FnProto token(FatArrow) Block2742FnDef : FnProto Block
2741*/2743*/
2742static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandatory) {2744static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandatory) {
2743 AstNode *fn_proto = ast_parse_fn_proto(pc, token_index, mandatory);2745 AstNode *fn_proto = ast_parse_fn_proto(pc, token_index, mandatory);
...@@ -2746,7 +2748,6 @@ static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandat...@@ -2746,7 +2748,6 @@ static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandat
2746 AstNode *node = ast_create_node_with_node(pc, NodeTypeFnDef, fn_proto);2748 AstNode *node = ast_create_node_with_node(pc, NodeTypeFnDef, fn_proto);
27472749
2748 node->data.fn_def.fn_proto = fn_proto;2750 node->data.fn_def.fn_proto = fn_proto;
2749 ast_eat_token(pc, token_index, TokenIdFatArrow);
2750 node->data.fn_def.body = ast_parse_block(pc, token_index, true);2751 node->data.fn_def.body = ast_parse_block(pc, token_index, true);
27512752
2752 normalize_parent_ptrs(node);2753 normalize_parent_ptrs(node);
std/bootstrap.zig+3-3
...@@ -8,14 +8,14 @@ var argv: &&u8 = undefined;...@@ -8,14 +8,14 @@ var argv: &&u8 = undefined;
8var env: &&u8 = undefined;8var env: &&u8 = undefined;
99
10#attribute("naked")10#attribute("naked")
11export fn _start() unreachable => {11export fn _start() -> unreachable {
12 argc = asm("mov (%%rsp), %[argc]": [argc] "=r" (-> isize));12 argc = asm("mov (%%rsp), %[argc]": [argc] "=r" (-> isize));
13 argv = asm("lea 0x8(%%rsp), %[argv]": [argv] "=r" (-> &&u8));13 argv = asm("lea 0x8(%%rsp), %[argv]": [argv] "=r" (-> &&u8));
14 env = asm("lea 0x10(%%rsp,%%rdi,8), %[env]": [env] "=r" (-> &&u8));14 env = asm("lea 0x10(%%rsp,%%rdi,8), %[env]": [env] "=r" (-> &&u8));
15 call_main()15 call_main()
16}16}
1717
18fn strlen(ptr: &const u8) isize => {18fn strlen(ptr: &const u8) -> isize {
19 var count: isize = 0;19 var count: isize = 0;
20 while (ptr[count] != 0) {20 while (ptr[count] != 0) {
21 count += 1;21 count += 1;
...@@ -23,7 +23,7 @@ fn strlen(ptr: &const u8) isize => {...@@ -23,7 +23,7 @@ fn strlen(ptr: &const u8) isize => {
23 return count;23 return count;
24}24}
2525
26fn call_main() unreachable => {26fn call_main() -> unreachable {
27 var args: [argc][]u8;27 var args: [argc][]u8;
28 for (arg, args, i) {28 for (arg, args, i) {
29 const ptr = argv[i];29 const ptr = argv[i];
std/builtin.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1// These functions are provided when not linking against libc because LLVM1// These functions are provided when not linking against libc because LLVM
2// sometimes generates code that calls them.2// sometimes generates code that calls them.
33
4export fn memset(dest: &u8, c: u8, n: isize) &u8 => {4export fn memset(dest: &u8, c: u8, n: isize) -> &u8 {
5 var index : @typeof(n) = 0;5 var index : @typeof(n) = 0;
6 while (index != n) {6 while (index != n) {
7 dest[index] = c;7 dest[index] = c;
...@@ -10,7 +10,7 @@ export fn memset(dest: &u8, c: u8, n: isize) &u8 => {...@@ -10,7 +10,7 @@ export fn memset(dest: &u8, c: u8, n: isize) &u8 => {
10 return dest;10 return dest;
11}11}
1212
13export fn memcpy(noalias dest: &u8, noalias src: &const u8, n: isize) &u8 => {13export fn memcpy(noalias dest: &u8, noalias src: &const u8, n: isize) -> &u8 {
14 var index : @typeof(n) = 0;14 var index : @typeof(n) = 0;
15 while (index != n) {15 while (index != n) {
16 dest[index] = src[index];16 dest[index] = src[index];
std/rand.zig+6-6
...@@ -7,7 +7,7 @@ pub struct Rand {...@@ -7,7 +7,7 @@ pub struct Rand {
7 index: isize,7 index: isize,
88
9 /// Get 32 bits of randomness.9 /// Get 32 bits of randomness.
10 pub fn get_u32(r: &Rand) u32 => {10 pub fn get_u32(r: &Rand) -> u32 {
11 if (r.index == 0) {11 if (r.index == 0) {
12 r.generate_numbers();12 r.generate_numbers();
13 }13 }
...@@ -24,7 +24,7 @@ pub struct Rand {...@@ -24,7 +24,7 @@ pub struct Rand {
24 }24 }
2525
26 /// Fill `buf` with randomness.26 /// Fill `buf` with randomness.
27 pub fn get_bytes(r: &Rand, buf: []u8) => {27 pub fn get_bytes(r: &Rand, buf: []u8) {
28 var bytes_left = r.get_bytes_aligned(buf);28 var bytes_left = r.get_bytes_aligned(buf);
29 if (bytes_left > 0) {29 if (bytes_left > 0) {
30 var rand_val_array : [@sizeof(u32)]u8;30 var rand_val_array : [@sizeof(u32)]u8;
...@@ -38,7 +38,7 @@ pub struct Rand {...@@ -38,7 +38,7 @@ pub struct Rand {
3838
39 /// Get a random unsigned integer with even distribution between `start`39 /// Get a random unsigned integer with even distribution between `start`
40 /// inclusive and `end` exclusive.40 /// inclusive and `end` exclusive.
41 pub fn range_u64(r: &Rand, start: u64, end: u64) u64 => {41 pub fn range_u64(r: &Rand, start: u64, end: u64) -> u64 {
42 const range = end - start;42 const range = end - start;
43 const leftover = @max_value(u64) % range;43 const leftover = @max_value(u64) % range;
44 const upper_bound = @max_value(u64) - leftover;44 const upper_bound = @max_value(u64) - leftover;
...@@ -53,7 +53,7 @@ pub struct Rand {...@@ -53,7 +53,7 @@ pub struct Rand {
53 }53 }
54 }54 }
5555
56 fn generate_numbers(r: &Rand) => {56 fn generate_numbers(r: &Rand) {
57 for (item, r.array, i) {57 for (item, r.array, i) {
58 const y : u32 = (item & 0x80000000) + (r.array[(i + 1) % ARRAY_SIZE] & 0x7fffffff);58 const y : u32 = (item & 0x80000000) + (r.array[(i + 1) % ARRAY_SIZE] & 0x7fffffff);
59 const untempered : u32 = r.array[(i + 397) % ARRAY_SIZE] ^ (y >> 1);59 const untempered : u32 = r.array[(i + 397) % ARRAY_SIZE] ^ (y >> 1);
...@@ -67,7 +67,7 @@ pub struct Rand {...@@ -67,7 +67,7 @@ pub struct Rand {
67 }67 }
6868
69 // does not populate the remaining (buf.len % 4) bytes69 // does not populate the remaining (buf.len % 4) bytes
70 fn get_bytes_aligned(r: &Rand, buf: []u8) isize => {70 fn get_bytes_aligned(r: &Rand, buf: []u8) -> isize {
71 var bytes_left = buf.len;71 var bytes_left = buf.len;
72 while (bytes_left >= 4) {72 while (bytes_left >= 4) {
73 *((&u32)(&buf[buf.len - bytes_left])) = r.get_u32();73 *((&u32)(&buf[buf.len - bytes_left])) = r.get_u32();
...@@ -78,7 +78,7 @@ pub struct Rand {...@@ -78,7 +78,7 @@ pub struct Rand {
78}78}
7979
80/// Initialize random state with the given seed.80/// Initialize random state with the given seed.
81pub fn rand_new(seed: u32) Rand => {81pub fn rand_new(seed: u32) -> Rand {
82 var r: Rand;82 var r: Rand;
83 r.index = 0;83 r.index = 0;
84 r.array[0] = seed;84 r.array[0] = seed;
std/std.zig+12-12
...@@ -50,7 +50,7 @@ pub struct OutStream {...@@ -50,7 +50,7 @@ pub struct OutStream {
50 index: isize,50 index: isize,
51 buffered: bool,51 buffered: bool,
5252
53 pub fn print_str(os: &OutStream, str: []const u8) %isize => {53 pub fn print_str(os: &OutStream, str: []const u8) -> %isize {
54 var src_bytes_left = str.len;54 var src_bytes_left = str.len;
55 var src_index: @typeof(str.len) = 0;55 var src_index: @typeof(str.len) = 0;
56 const dest_space_left = os.buffer.len - os.index;56 const dest_space_left = os.buffer.len - os.index;
...@@ -72,13 +72,13 @@ pub struct OutStream {...@@ -72,13 +72,13 @@ pub struct OutStream {
7272
73 /// Prints a byte buffer, flushes the buffer, then returns the number of73 /// Prints a byte buffer, flushes the buffer, then returns the number of
74 /// bytes printed. The "f" is for "flush".74 /// bytes printed. The "f" is for "flush".
75 pub fn printf(os: &OutStream, str: []const u8) %isize => {75 pub fn printf(os: &OutStream, str: []const u8) -> %isize {
76 const byte_count = %return os.print_str(str);76 const byte_count = %return os.print_str(str);
77 %return os.flush();77 %return os.flush();
78 return byte_count;78 return byte_count;
79 }79 }
8080
81 pub fn print_u64(os: &OutStream, x: u64) %isize => {81 pub fn print_u64(os: &OutStream, x: u64) -> %isize {
82 if (os.index + max_u64_base10_digits >= os.buffer.len) {82 if (os.index + max_u64_base10_digits >= os.buffer.len) {
83 %return os.flush();83 %return os.flush();
84 }84 }
...@@ -93,7 +93,7 @@ pub struct OutStream {...@@ -93,7 +93,7 @@ pub struct OutStream {
93 }93 }
9494
9595
96 pub fn print_i64(os: &OutStream, x: i64) %isize => {96 pub fn print_i64(os: &OutStream, x: i64) -> %isize {
97 if (os.index + max_u64_base10_digits >= os.buffer.len) {97 if (os.index + max_u64_base10_digits >= os.buffer.len) {
98 %return os.flush();98 %return os.flush();
99 }99 }
...@@ -108,7 +108,7 @@ pub struct OutStream {...@@ -108,7 +108,7 @@ pub struct OutStream {
108 }108 }
109109
110110
111 pub fn flush(os: &OutStream) %void => {111 pub fn flush(os: &OutStream) -> %void {
112 const amt_written = write(os.fd, os.buffer.ptr, os.index);112 const amt_written = write(os.fd, os.buffer.ptr, os.index);
113 os.index = 0;113 os.index = 0;
114 if (amt_written < 0) {114 if (amt_written < 0) {
...@@ -130,7 +130,7 @@ pub struct OutStream {...@@ -130,7 +130,7 @@ pub struct OutStream {
130pub struct InStream {130pub struct InStream {
131 fd: isize,131 fd: isize,
132132
133 pub fn read(is: &InStream, buf: []u8) %isize => {133 pub fn read(is: &InStream, buf: []u8) -> %isize {
134 const amt_read = read(is.fd, buf.ptr, buf.len);134 const amt_read = read(is.fd, buf.ptr, buf.len);
135 if (amt_read < 0) {135 if (amt_read < 0) {
136 return switch (-amt_read) {136 return switch (-amt_read) {
...@@ -146,7 +146,7 @@ pub struct InStream {...@@ -146,7 +146,7 @@ pub struct InStream {
146 }146 }
147}147}
148148
149pub fn os_get_random_bytes(buf: []u8) %void => {149pub fn os_get_random_bytes(buf: []u8) -> %void {
150 const amt_got = getrandom(buf.ptr, buf.len, 0);150 const amt_got = getrandom(buf.ptr, buf.len, 0);
151 if (amt_got < 0) {151 if (amt_got < 0) {
152 return switch (-amt_got) {152 return switch (-amt_got) {
...@@ -162,7 +162,7 @@ pub fn os_get_random_bytes(buf: []u8) %void => {...@@ -162,7 +162,7 @@ pub fn os_get_random_bytes(buf: []u8) %void => {
162pub error InvalidChar;162pub error InvalidChar;
163pub error Overflow;163pub error Overflow;
164164
165pub fn parse_u64(buf: []u8, radix: u8) %u64 => {165pub fn parse_u64(buf: []u8, radix: u8) -> %u64 {
166 var x : u64 = 0;166 var x : u64 = 0;
167167
168 for (c, buf) {168 for (c, buf) {
...@@ -186,7 +186,7 @@ pub fn parse_u64(buf: []u8, radix: u8) %u64 => {...@@ -186,7 +186,7 @@ pub fn parse_u64(buf: []u8, radix: u8) %u64 => {
186 return x;186 return x;
187}187}
188188
189fn char_to_digit(c: u8) u8 => {189fn char_to_digit(c: u8) -> u8 {
190 // TODO use switch with range190 // TODO use switch with range
191 if ('0' <= c && c <= '9') {191 if ('0' <= c && c <= '9') {
192 c - '0'192 c - '0'
...@@ -199,7 +199,7 @@ fn char_to_digit(c: u8) u8 => {...@@ -199,7 +199,7 @@ fn char_to_digit(c: u8) u8 => {
199 }199 }
200}200}
201201
202fn buf_print_i64(out_buf: []u8, x: i64) isize => {202fn buf_print_i64(out_buf: []u8, x: i64) -> isize {
203 if (x < 0) {203 if (x < 0) {
204 out_buf[0] = '-';204 out_buf[0] = '-';
205 return 1 + buf_print_u64(out_buf[1...], u64(-(x + 1)) + 1);205 return 1 + buf_print_u64(out_buf[1...], u64(-(x + 1)) + 1);
...@@ -208,7 +208,7 @@ fn buf_print_i64(out_buf: []u8, x: i64) isize => {...@@ -208,7 +208,7 @@ fn buf_print_i64(out_buf: []u8, x: i64) isize => {
208 }208 }
209}209}
210210
211fn buf_print_u64(out_buf: []u8, x: u64) isize => {211fn buf_print_u64(out_buf: []u8, x: u64) -> isize {
212 var buf: [max_u64_base10_digits]u8;212 var buf: [max_u64_base10_digits]u8;
213 var a = x;213 var a = x;
214 var index = buf.len;214 var index = buf.len;
...@@ -229,6 +229,6 @@ fn buf_print_u64(out_buf: []u8, x: u64) isize => {...@@ -229,6 +229,6 @@ fn buf_print_u64(out_buf: []u8, x: u64) isize => {
229 return len;229 return len;
230}230}
231231
232fn min_isize(x: isize, y: isize) isize => {232fn min_isize(x: isize, y: isize) -> isize {
233 if (x < y) x else y233 if (x < y) x else y
234}234}
std/syscall.zig+6-6
...@@ -3,33 +3,33 @@ const SYS_write = 1;...@@ -3,33 +3,33 @@ const SYS_write = 1;
3const SYS_exit = 60;3const SYS_exit = 60;
4const SYS_getrandom = 318;4const SYS_getrandom = 318;
55
6fn syscall1(number: isize, arg1: isize) isize => {6fn syscall1(number: isize, arg1: isize) -> isize {
7 asm volatile ("syscall"7 asm volatile ("syscall"
8 : [ret] "={rax}" (-> isize)8 : [ret] "={rax}" (-> isize)
9 : [number] "{rax}" (number), [arg1] "{rdi}" (arg1)9 : [number] "{rax}" (number), [arg1] "{rdi}" (arg1)
10 : "rcx", "r11")10 : "rcx", "r11")
11}11}
1212
13fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) isize => {13fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> isize {
14 asm volatile ("syscall"14 asm volatile ("syscall"
15 : [ret] "={rax}" (-> isize)15 : [ret] "={rax}" (-> isize)
16 : [number] "{rax}" (number), [arg1] "{rdi}" (arg1), [arg2] "{rsi}" (arg2), [arg3] "{rdx}" (arg3)16 : [number] "{rax}" (number), [arg1] "{rdi}" (arg1), [arg2] "{rsi}" (arg2), [arg3] "{rdx}" (arg3)
17 : "rcx", "r11")17 : "rcx", "r11")
18}18}
1919
20pub fn read(fd: isize, buf: &u8, count: isize) isize => {20pub fn read(fd: isize, buf: &u8, count: isize) -> isize {
21 syscall3(SYS_read, isize(fd), isize(buf), count)21 syscall3(SYS_read, isize(fd), isize(buf), count)
22}22}
2323
24pub fn write(fd: isize, buf: &const u8, count: isize) isize => {24pub fn write(fd: isize, buf: &const u8, count: isize) -> isize {
25 syscall3(SYS_write, isize(fd), isize(buf), count)25 syscall3(SYS_write, isize(fd), isize(buf), count)
26}26}
2727
28pub fn exit(status: i32) unreachable => {28pub fn exit(status: i32) -> unreachable {
29 syscall1(SYS_exit, isize(status));29 syscall1(SYS_exit, isize(status));
30 unreachable{}30 unreachable{}
31}31}
3232
33pub fn getrandom(buf: &u8, count: isize, flags: u32) isize => {33pub fn getrandom(buf: &u8, count: isize, flags: u32) -> isize {
34 syscall3(SYS_getrandom, isize(buf), count, isize(flags))34 syscall3(SYS_getrandom, isize(buf), count, isize(flags))
35}35}
test/run_tests.cpp+133-133
...@@ -98,10 +98,10 @@ static void add_compiling_test_cases(void) {...@@ -98,10 +98,10 @@ static void add_compiling_test_cases(void) {
98 add_simple_case("hello world with libc", R"SOURCE(98 add_simple_case("hello world with libc", R"SOURCE(
99#link("c")99#link("c")
100extern {100extern {
101 fn puts(s: &const u8) i32;101 fn puts(s: &const u8) -> i32;
102}102}
103103
104export fn main(argc: i32, argv: &&u8) i32 => {104export fn main(argc: i32, argv: &&u8) -> i32 {
105 puts(c"Hello, world!");105 puts(c"Hello, world!");
106 return 0;106 return 0;
107}107}
...@@ -111,16 +111,16 @@ export fn main(argc: i32, argv: &&u8) i32 => {...@@ -111,16 +111,16 @@ export fn main(argc: i32, argv: &&u8) i32 => {
111import "std.zig";111import "std.zig";
112import "syscall.zig";112import "syscall.zig";
113113
114fn empty_function_1() => {}114fn empty_function_1() {}
115fn empty_function_2() => { return; }115fn empty_function_2() { return; }
116116
117pub fn main(args: [][]u8) %void => {117pub fn main(args: [][]u8) -> %void {
118 empty_function_1();118 empty_function_1();
119 empty_function_2();119 empty_function_2();
120 this_is_a_function();120 this_is_a_function();
121}121}
122122
123fn this_is_a_function() unreachable => {123fn this_is_a_function() -> unreachable {
124 stdout.printf("OK\n");124 stdout.printf("OK\n");
125 exit(0);125 exit(0);
126}126}
...@@ -132,11 +132,11 @@ import "std.zig";...@@ -132,11 +132,11 @@ import "std.zig";
132/**132/**
133 * multi line doc comment133 * multi line doc comment
134 */134 */
135fn another_function() => {}135fn another_function() {}
136136
137/// this is a documentation comment137/// this is a documentation comment
138/// doc comment line 2138/// doc comment line 2
139pub fn main(args: [][]u8) %void => {139pub fn main(args: [][]u8) -> %void {
140 stdout.printf(/* mid-line comment /* nested */ */ "OK\n");140 stdout.printf(/* mid-line comment /* nested */ */ "OK\n");
141}141}
142 )SOURCE", "OK\n");142 )SOURCE", "OK\n");
...@@ -146,12 +146,12 @@ pub fn main(args: [][]u8) %void => {...@@ -146,12 +146,12 @@ pub fn main(args: [][]u8) %void => {
146import "std.zig";146import "std.zig";
147import "foo.zig";147import "foo.zig";
148148
149pub fn main(args: [][]u8) %void => {149pub fn main(args: [][]u8) -> %void {
150 private_function();150 private_function();
151 stdout.printf("OK 2\n");151 stdout.printf("OK 2\n");
152}152}
153153
154fn private_function() => {154fn private_function() {
155 print_text();155 print_text();
156}156}
157 )SOURCE", "OK 1\nOK 2\n");157 )SOURCE", "OK 1\nOK 2\n");
...@@ -161,11 +161,11 @@ import "std.zig";...@@ -161,11 +161,11 @@ import "std.zig";
161161
162// purposefully conflicting function with main.zig162// purposefully conflicting function with main.zig
163// but it's private so it should be OK163// but it's private so it should be OK
164fn private_function() => {164fn private_function() {
165 stdout.printf("OK 1\n");165 stdout.printf("OK 1\n");
166}166}
167167
168pub fn print_text() => {168pub fn print_text() {
169 private_function();169 private_function();
170}170}
171 )SOURCE");171 )SOURCE");
...@@ -176,7 +176,7 @@ pub fn print_text() => {...@@ -176,7 +176,7 @@ pub fn print_text() => {
176import "foo.zig";176import "foo.zig";
177import "bar.zig";177import "bar.zig";
178178
179pub fn main(args: [][]u8) %void => {179pub fn main(args: [][]u8) -> %void {
180 foo_function();180 foo_function();
181 bar_function();181 bar_function();
182}182}
...@@ -184,7 +184,7 @@ pub fn main(args: [][]u8) %void => {...@@ -184,7 +184,7 @@ pub fn main(args: [][]u8) %void => {
184184
185 add_source_file(tc, "foo.zig", R"SOURCE(185 add_source_file(tc, "foo.zig", R"SOURCE(
186import "std.zig";186import "std.zig";
187pub fn foo_function() => {187pub fn foo_function() {
188 stdout.printf("OK\n");188 stdout.printf("OK\n");
189}189}
190 )SOURCE");190 )SOURCE");
...@@ -193,7 +193,7 @@ pub fn foo_function() => {...@@ -193,7 +193,7 @@ pub fn foo_function() => {
193import "other.zig";193import "other.zig";
194import "std.zig";194import "std.zig";
195195
196pub fn bar_function() => {196pub fn bar_function() {
197 if (foo_function()) {197 if (foo_function()) {
198 stdout.printf("OK\n");198 stdout.printf("OK\n");
199 }199 }
...@@ -201,7 +201,7 @@ pub fn bar_function() => {...@@ -201,7 +201,7 @@ pub fn bar_function() => {
201 )SOURCE");201 )SOURCE");
202202
203 add_source_file(tc, "other.zig", R"SOURCE(203 add_source_file(tc, "other.zig", R"SOURCE(
204pub fn foo_function() bool => {204pub fn foo_function() -> bool {
205 // this one conflicts with the one from foo205 // this one conflicts with the one from foo
206 return true;206 return true;
207}207}
...@@ -211,7 +211,7 @@ pub fn foo_function() bool => {...@@ -211,7 +211,7 @@ pub fn foo_function() bool => {
211 add_simple_case("if statements", R"SOURCE(211 add_simple_case("if statements", R"SOURCE(
212import "std.zig";212import "std.zig";
213213
214pub fn main(args: [][]u8) %void => {214pub fn main(args: [][]u8) -> %void {
215 if (1 != 0) {215 if (1 != 0) {
216 stdout.printf("1 is true\n");216 stdout.printf("1 is true\n");
217 } else {217 } else {
...@@ -231,11 +231,11 @@ pub fn main(args: [][]u8) %void => {...@@ -231,11 +231,11 @@ pub fn main(args: [][]u8) %void => {
231 add_simple_case("params", R"SOURCE(231 add_simple_case("params", R"SOURCE(
232import "std.zig";232import "std.zig";
233233
234fn add(a: i32, b: i32) i32 => {234fn add(a: i32, b: i32) -> i32 {
235 a + b235 a + b
236}236}
237237
238pub fn main(args: [][]u8) %void => {238pub fn main(args: [][]u8) -> %void {
239 if (add(22, 11) == 33) {239 if (add(22, 11) == 33) {
240 stdout.printf("pass\n");240 stdout.printf("pass\n");
241 }241 }
...@@ -245,7 +245,7 @@ pub fn main(args: [][]u8) %void => {...@@ -245,7 +245,7 @@ pub fn main(args: [][]u8) %void => {
245 add_simple_case("goto", R"SOURCE(245 add_simple_case("goto", R"SOURCE(
246import "std.zig";246import "std.zig";
247247
248fn loop(a : i32) => {248fn loop(a : i32) {
249 if (a == 0) {249 if (a == 0) {
250 goto done;250 goto done;
251 }251 }
...@@ -256,7 +256,7 @@ done:...@@ -256,7 +256,7 @@ done:
256 return;256 return;
257}257}
258258
259pub fn main(args: [][]u8) %void => {259pub fn main(args: [][]u8) -> %void {
260 loop(3);260 loop(3);
261}261}
262 )SOURCE", "loop\nloop\nloop\n");262 )SOURCE", "loop\nloop\nloop\n");
...@@ -264,7 +264,7 @@ pub fn main(args: [][]u8) %void => {...@@ -264,7 +264,7 @@ pub fn main(args: [][]u8) %void => {
264 add_simple_case("local variables", R"SOURCE(264 add_simple_case("local variables", R"SOURCE(
265import "std.zig";265import "std.zig";
266266
267pub fn main(args: [][]u8) %void => {267pub fn main(args: [][]u8) -> %void {
268 const a : i32 = 1;268 const a : i32 = 1;
269 const b = i32(2);269 const b = i32(2);
270 if (a + b == 3) {270 if (a + b == 3) {
...@@ -276,7 +276,7 @@ pub fn main(args: [][]u8) %void => {...@@ -276,7 +276,7 @@ pub fn main(args: [][]u8) %void => {
276 add_simple_case("bool literals", R"SOURCE(276 add_simple_case("bool literals", R"SOURCE(
277import "std.zig";277import "std.zig";
278278
279pub fn main(args: [][]u8) %void => {279pub fn main(args: [][]u8) -> %void {
280 if (true) { stdout.printf("OK 1\n"); }280 if (true) { stdout.printf("OK 1\n"); }
281 if (false) { stdout.printf("BAD 1\n"); }281 if (false) { stdout.printf("BAD 1\n"); }
282 if (!true) { stdout.printf("BAD 2\n"); }282 if (!true) { stdout.printf("BAD 2\n"); }
...@@ -287,7 +287,7 @@ pub fn main(args: [][]u8) %void => {...@@ -287,7 +287,7 @@ pub fn main(args: [][]u8) %void => {
287 add_simple_case("separate block scopes", R"SOURCE(287 add_simple_case("separate block scopes", R"SOURCE(
288import "std.zig";288import "std.zig";
289289
290pub fn main(args: [][]u8) %void => {290pub fn main(args: [][]u8) -> %void {
291 if (true) {291 if (true) {
292 const no_conflict : i32 = 5;292 const no_conflict : i32 = 5;
293 if (no_conflict == 5) { stdout.printf("OK 1\n"); }293 if (no_conflict == 5) { stdout.printf("OK 1\n"); }
...@@ -304,11 +304,11 @@ pub fn main(args: [][]u8) %void => {...@@ -304,11 +304,11 @@ pub fn main(args: [][]u8) %void => {
304 add_simple_case("void parameters", R"SOURCE(304 add_simple_case("void parameters", R"SOURCE(
305import "std.zig";305import "std.zig";
306306
307pub fn main(args: [][]u8) %void => {307pub fn main(args: [][]u8) -> %void {
308 void_fun(1, void{}, 2);308 void_fun(1, void{}, 2);
309}309}
310310
311fn void_fun(a : i32, b : void, c : i32) => {311fn void_fun(a : i32, b : void, c : i32) {
312 const v = b;312 const v = b;
313 const vv : void = if (a == 1) {v} else {};313 const vv : void = if (a == 1) {v} else {};
314 if (a + c == 3) { stdout.printf("OK\n"); }314 if (a + c == 3) { stdout.printf("OK\n"); }
...@@ -323,7 +323,7 @@ struct Foo {...@@ -323,7 +323,7 @@ struct Foo {
323 b : i32,323 b : i32,
324 c : void,324 c : void,
325}325}
326pub fn main(args: [][]u8) %void => {326pub fn main(args: [][]u8) -> %void {
327 const foo = Foo {327 const foo = Foo {
328 .a = void{},328 .a = void{},
329 .b = 1,329 .b = 1,
...@@ -343,7 +343,7 @@ pub fn main(args: [][]u8) %void => {...@@ -343,7 +343,7 @@ pub fn main(args: [][]u8) %void => {
343 add_simple_case("void arrays", R"SOURCE(343 add_simple_case("void arrays", R"SOURCE(
344import "std.zig";344import "std.zig";
345345
346pub fn main(args: [][]u8) %void => {346pub fn main(args: [][]u8) -> %void {
347 var array: [4]void;347 var array: [4]void;
348 array[0] = void{};348 array[0] = void{};
349 array[1] = array[2];349 array[1] = array[2];
...@@ -361,7 +361,7 @@ pub fn main(args: [][]u8) %void => {...@@ -361,7 +361,7 @@ pub fn main(args: [][]u8) %void => {
361 add_simple_case("mutable local variables", R"SOURCE(361 add_simple_case("mutable local variables", R"SOURCE(
362import "std.zig";362import "std.zig";
363363
364pub fn main(args: [][]u8) %void => {364pub fn main(args: [][]u8) -> %void {
365 var zero : i32 = 0;365 var zero : i32 = 0;
366 if (zero == 0) { stdout.printf("zero\n"); }366 if (zero == 0) { stdout.printf("zero\n"); }
367367
...@@ -376,7 +376,7 @@ pub fn main(args: [][]u8) %void => {...@@ -376,7 +376,7 @@ pub fn main(args: [][]u8) %void => {
376 add_simple_case("arrays", R"SOURCE(376 add_simple_case("arrays", R"SOURCE(
377import "std.zig";377import "std.zig";
378378
379pub fn main(args: [][]u8) %void => {379pub fn main(args: [][]u8) -> %void {
380 var array : [5]i32;380 var array : [5]i32;
381381
382 var i : i32 = 0;382 var i : i32 = 0;
...@@ -401,7 +401,7 @@ pub fn main(args: [][]u8) %void => {...@@ -401,7 +401,7 @@ pub fn main(args: [][]u8) %void => {
401 stdout.printf("BAD\n");401 stdout.printf("BAD\n");
402 }402 }
403}403}
404fn get_array_len(a: []i32) isize => {404fn get_array_len(a: []i32) -> isize {
405 a.len405 a.len
406}406}
407 )SOURCE", "OK\n");407 )SOURCE", "OK\n");
...@@ -410,7 +410,7 @@ fn get_array_len(a: []i32) isize => {...@@ -410,7 +410,7 @@ fn get_array_len(a: []i32) isize => {
410 add_simple_case("hello world without libc", R"SOURCE(410 add_simple_case("hello world without libc", R"SOURCE(
411import "std.zig";411import "std.zig";
412412
413pub fn main(args: [][]u8) %void => {413pub fn main(args: [][]u8) -> %void {
414 stdout.printf("Hello, world!\n");414 stdout.printf("Hello, world!\n");
415}415}
416 )SOURCE", "Hello, world!\n");416 )SOURCE", "Hello, world!\n");
...@@ -419,7 +419,7 @@ pub fn main(args: [][]u8) %void => {...@@ -419,7 +419,7 @@ pub fn main(args: [][]u8) %void => {
419 add_simple_case("a + b + c", R"SOURCE(419 add_simple_case("a + b + c", R"SOURCE(
420import "std.zig";420import "std.zig";
421421
422pub fn main(args: [][]u8) %void => {422pub fn main(args: [][]u8) -> %void {
423 if (false || false || false) { stdout.printf("BAD 1\n"); }423 if (false || false || false) { stdout.printf("BAD 1\n"); }
424 if (true && true && false) { stdout.printf("BAD 2\n"); }424 if (true && true && false) { stdout.printf("BAD 2\n"); }
425 if (1 | 2 | 4 != 7) { stdout.printf("BAD 3\n"); }425 if (1 | 2 | 4 != 7) { stdout.printf("BAD 3\n"); }
...@@ -440,7 +440,7 @@ pub fn main(args: [][]u8) %void => {...@@ -440,7 +440,7 @@ pub fn main(args: [][]u8) %void => {
440 add_simple_case("short circuit", R"SOURCE(440 add_simple_case("short circuit", R"SOURCE(
441import "std.zig";441import "std.zig";
442442
443pub fn main(args: [][]u8) %void => {443pub fn main(args: [][]u8) -> %void {
444 if (true || { stdout.printf("BAD 1\n"); false }) {444 if (true || { stdout.printf("BAD 1\n"); false }) {
445 stdout.printf("OK 1\n");445 stdout.printf("OK 1\n");
446 }446 }
...@@ -461,7 +461,7 @@ pub fn main(args: [][]u8) %void => {...@@ -461,7 +461,7 @@ pub fn main(args: [][]u8) %void => {
461 add_simple_case("modify operators", R"SOURCE(461 add_simple_case("modify operators", R"SOURCE(
462import "std.zig";462import "std.zig";
463463
464pub fn main(args: [][]u8) %void => {464pub fn main(args: [][]u8) -> %void {
465 var i : i32 = 0;465 var i : i32 = 0;
466 i += 5; if (i != 5) { stdout.printf("BAD +=\n"); }466 i += 5; if (i != 5) { stdout.printf("BAD +=\n"); }
467 i -= 2; if (i != 3) { stdout.printf("BAD -=\n"); }467 i -= 2; if (i != 3) { stdout.printf("BAD -=\n"); }
...@@ -483,10 +483,10 @@ pub fn main(args: [][]u8) %void => {...@@ -483,10 +483,10 @@ pub fn main(args: [][]u8) %void => {
483 add_simple_case("number literals", R"SOURCE(483 add_simple_case("number literals", R"SOURCE(
484#link("c")484#link("c")
485extern {485extern {
486 fn printf(__format: &const u8, ...) i32;486 fn printf(__format: &const u8, ...) -> i32;
487}487}
488488
489export fn main(argc: i32, argv: &&u8) i32 => {489export fn main(argc: i32, argv: &&u8) -> i32 {
490 printf(c"\n");490 printf(c"\n");
491491
492 printf(c"0: %llu\n",492 printf(c"0: %llu\n",
...@@ -612,7 +612,7 @@ export fn main(argc: i32, argv: &&u8) i32 => {...@@ -612,7 +612,7 @@ export fn main(argc: i32, argv: &&u8) i32 => {
612 add_simple_case("structs", R"SOURCE(612 add_simple_case("structs", R"SOURCE(
613import "std.zig";613import "std.zig";
614614
615pub fn main(args: [][]u8) %void => {615pub fn main(args: [][]u8) -> %void {
616 var foo : Foo;616 var foo : Foo;
617 @memset(&foo, 0, @sizeof(Foo));617 @memset(&foo, 0, @sizeof(Foo));
618 foo.a += 1;618 foo.a += 1;
...@@ -632,12 +632,12 @@ struct Foo {...@@ -632,12 +632,12 @@ struct Foo {
632 b : bool,632 b : bool,
633 c : f32,633 c : f32,
634}634}
635fn test_foo(foo : Foo) => {635fn test_foo(foo : Foo) {
636 if (!foo.b) {636 if (!foo.b) {
637 stdout.printf("BAD\n");637 stdout.printf("BAD\n");
638 }638 }
639}639}
640fn test_mutation(foo : &Foo) => {640fn test_mutation(foo : &Foo) {
641 foo.c = 100;641 foo.c = 100;
642}642}
643struct Node {643struct Node {
...@@ -648,7 +648,7 @@ struct Node {...@@ -648,7 +648,7 @@ struct Node {
648struct Val {648struct Val {
649 x: i32,649 x: i32,
650}650}
651fn test_point_to_self() => {651fn test_point_to_self() {
652 var root : Node;652 var root : Node;
653 root.val.x = 1;653 root.val.x = 1;
654654
...@@ -662,7 +662,7 @@ fn test_point_to_self() => {...@@ -662,7 +662,7 @@ fn test_point_to_self() => {
662 stdout.printf("BAD\n");662 stdout.printf("BAD\n");
663 }663 }
664}664}
665fn test_byval_assign() => {665fn test_byval_assign() {
666 var foo1 : Foo;666 var foo1 : Foo;
667 var foo2 : Foo;667 var foo2 : Foo;
668668
...@@ -674,7 +674,7 @@ fn test_byval_assign() => {...@@ -674,7 +674,7 @@ fn test_byval_assign() => {
674674
675 if (foo2.a != 1234) { stdout.printf("BAD - byval assignment failed\n"); }675 if (foo2.a != 1234) { stdout.printf("BAD - byval assignment failed\n"); }
676}676}
677fn test_initializer() => {677fn test_initializer() {
678 const val = Val { .x = 42 };678 const val = Val { .x = 42 };
679 if (val.x != 42) { stdout.printf("BAD\n"); }679 if (val.x != 42) { stdout.printf("BAD\n"); }
680}680}
...@@ -686,7 +686,7 @@ import "std.zig";...@@ -686,7 +686,7 @@ import "std.zig";
686const g1 : i32 = 1233 + 1;686const g1 : i32 = 1233 + 1;
687var g2 : i32 = 0;687var g2 : i32 = 0;
688688
689pub fn main(args: [][]u8) %void => {689pub fn main(args: [][]u8) -> %void {
690 if (g2 != 0) { stdout.printf("BAD\n"); }690 if (g2 != 0) { stdout.printf("BAD\n"); }
691 g2 = g1;691 g2 = g1;
692 if (g2 != 1234) { stdout.printf("BAD\n"); }692 if (g2 != 1234) { stdout.printf("BAD\n"); }
...@@ -696,7 +696,7 @@ pub fn main(args: [][]u8) %void => {...@@ -696,7 +696,7 @@ pub fn main(args: [][]u8) %void => {
696696
697 add_simple_case("while loop", R"SOURCE(697 add_simple_case("while loop", R"SOURCE(
698import "std.zig";698import "std.zig";
699pub fn main(args: [][]u8) %void => {699pub fn main(args: [][]u8) -> %void {
700 var i : i32 = 0;700 var i : i32 = 0;
701 while (i < 4) {701 while (i < 4) {
702 stdout.printf("loop\n");702 stdout.printf("loop\n");
...@@ -704,10 +704,10 @@ pub fn main(args: [][]u8) %void => {...@@ -704,10 +704,10 @@ pub fn main(args: [][]u8) %void => {
704 }704 }
705 g();705 g();
706}706}
707fn g() i32 => {707fn g() -> i32 {
708 return f();708 return f();
709}709}
710fn f() i32 => {710fn f() -> i32 {
711 while (true) {711 while (true) {
712 return 0;712 return 0;
713 }713 }
...@@ -716,7 +716,7 @@ fn f() i32 => {...@@ -716,7 +716,7 @@ fn f() i32 => {
716716
717 add_simple_case("continue and break", R"SOURCE(717 add_simple_case("continue and break", R"SOURCE(
718import "std.zig";718import "std.zig";
719pub fn main(args: [][]u8) %void => {719pub fn main(args: [][]u8) -> %void {
720 var i : i32 = 0;720 var i : i32 = 0;
721 while (true) {721 while (true) {
722 stdout.printf("loop\n");722 stdout.printf("loop\n");
...@@ -731,7 +731,7 @@ pub fn main(args: [][]u8) %void => {...@@ -731,7 +731,7 @@ pub fn main(args: [][]u8) %void => {
731731
732 add_simple_case("maybe type", R"SOURCE(732 add_simple_case("maybe type", R"SOURCE(
733import "std.zig";733import "std.zig";
734pub fn main(args: [][]u8) %void => {734pub fn main(args: [][]u8) -> %void {
735 const x : ?bool = true;735 const x : ?bool = true;
736736
737 if (const y ?= x) {737 if (const y ?= x) {
...@@ -764,14 +764,14 @@ pub fn main(args: [][]u8) %void => {...@@ -764,14 +764,14 @@ pub fn main(args: [][]u8) %void => {
764764
765 add_simple_case("implicit cast after unreachable", R"SOURCE(765 add_simple_case("implicit cast after unreachable", R"SOURCE(
766import "std.zig";766import "std.zig";
767pub fn main(args: [][]u8) %void => {767pub fn main(args: [][]u8) -> %void {
768 const x = outer();768 const x = outer();
769 if (x == 1234) {769 if (x == 1234) {
770 stdout.printf("OK\n");770 stdout.printf("OK\n");
771 }771 }
772}772}
773fn inner() i32 => { 1234 }773fn inner() -> i32 { 1234 }
774fn outer() isize => {774fn outer() -> isize {
775 return inner();775 return inner();
776}776}
777 )SOURCE", "OK\n");777 )SOURCE", "OK\n");
...@@ -780,7 +780,7 @@ fn outer() isize => {...@@ -780,7 +780,7 @@ fn outer() isize => {
780import "std.zig";780import "std.zig";
781const x: u16 = 13;781const x: u16 = 13;
782const z: @typeof(x) = 19;782const z: @typeof(x) = 19;
783pub fn main(args: [][]u8) %void => {783pub fn main(args: [][]u8) -> %void {
784 const y: @typeof(x) = 120;784 const y: @typeof(x) = 120;
785 stdout.print_u64(@sizeof(@typeof(y)));785 stdout.print_u64(@sizeof(@typeof(y)));
786 stdout.printf("\n");786 stdout.printf("\n");
...@@ -791,11 +791,11 @@ pub fn main(args: [][]u8) %void => {...@@ -791,11 +791,11 @@ pub fn main(args: [][]u8) %void => {
791import "std.zig";791import "std.zig";
792struct Rand {792struct Rand {
793 seed: u32,793 seed: u32,
794 pub fn get_seed(r: Rand) u32 => {794 pub fn get_seed(r: Rand) -> u32 {
795 r.seed795 r.seed
796 }796 }
797}797}
798pub fn main(args: [][]u8) %void => {798pub fn main(args: [][]u8) -> %void {
799 const r = Rand {.seed = 1234};799 const r = Rand {.seed = 1234};
800 if (r.get_seed() != 1234) {800 if (r.get_seed() != 1234) {
801 stdout.printf("BAD seed\n");801 stdout.printf("BAD seed\n");
...@@ -807,7 +807,7 @@ pub fn main(args: [][]u8) %void => {...@@ -807,7 +807,7 @@ pub fn main(args: [][]u8) %void => {
807 add_simple_case("pointer dereferencing", R"SOURCE(807 add_simple_case("pointer dereferencing", R"SOURCE(
808import "std.zig";808import "std.zig";
809809
810pub fn main(args: [][]u8) %void => {810pub fn main(args: [][]u8) -> %void {
811 var x = i32(3);811 var x = i32(3);
812 const y = &x;812 const y = &x;
813813
...@@ -828,7 +828,7 @@ import "std.zig";...@@ -828,7 +828,7 @@ import "std.zig";
828828
829const ARRAY_SIZE : i8 = 20;829const ARRAY_SIZE : i8 = 20;
830830
831pub fn main(args: [][]u8) %void => {831pub fn main(args: [][]u8) -> %void {
832 var array : [ARRAY_SIZE]u8;832 var array : [ARRAY_SIZE]u8;
833 stdout.print_u64(@sizeof(@typeof(array)));833 stdout.print_u64(@sizeof(@typeof(array)));
834 stdout.printf("\n");834 stdout.printf("\n");
...@@ -837,7 +837,7 @@ pub fn main(args: [][]u8) %void => {...@@ -837,7 +837,7 @@ pub fn main(args: [][]u8) %void => {
837837
838 add_simple_case("@min_value() and @max_value()", R"SOURCE(838 add_simple_case("@min_value() and @max_value()", R"SOURCE(
839import "std.zig";839import "std.zig";
840pub fn main(args: [][]u8) %void => {840pub fn main(args: [][]u8) -> %void {
841 stdout.printf("max u8: ");841 stdout.printf("max u8: ");
842 stdout.print_u64(@max_value(u8));842 stdout.print_u64(@max_value(u8));
843 stdout.printf("\n");843 stdout.printf("\n");
...@@ -923,7 +923,7 @@ pub fn main(args: [][]u8) %void => {...@@ -923,7 +923,7 @@ pub fn main(args: [][]u8) %void => {
923923
924 add_simple_case("slicing", R"SOURCE(924 add_simple_case("slicing", R"SOURCE(
925import "std.zig";925import "std.zig";
926pub fn main(args: [][]u8) %void => {926pub fn main(args: [][]u8) -> %void {
927 var array : [20]i32;927 var array : [20]i32;
928928
929 array[5] = 1234;929 array[5] = 1234;
...@@ -950,12 +950,12 @@ pub fn main(args: [][]u8) %void => {...@@ -950,12 +950,12 @@ pub fn main(args: [][]u8) %void => {
950950
951 add_simple_case("else if expression", R"SOURCE(951 add_simple_case("else if expression", R"SOURCE(
952import "std.zig";952import "std.zig";
953pub fn main(args: [][]u8) %void => {953pub fn main(args: [][]u8) -> %void {
954 if (f(1) == 1) {954 if (f(1) == 1) {
955 stdout.printf("OK\n");955 stdout.printf("OK\n");
956 }956 }
957}957}
958fn f(c: u8) u8 => {958fn f(c: u8) -> u8 {
959 if (c == 0) {959 if (c == 0) {
960 0960 0
961 } else if (c == 1) {961 } else if (c == 1) {
...@@ -968,7 +968,7 @@ fn f(c: u8) u8 => {...@@ -968,7 +968,7 @@ fn f(c: u8) u8 => {
968968
969 add_simple_case("overflow intrinsics", R"SOURCE(969 add_simple_case("overflow intrinsics", R"SOURCE(
970import "std.zig";970import "std.zig";
971pub fn main(args: [][]u8) %void => {971pub fn main(args: [][]u8) -> %void {
972 var result: u8;972 var result: u8;
973 if (!@add_with_overflow(u8, 250, 100, &result)) {973 if (!@add_with_overflow(u8, 250, 100, &result)) {
974 stdout.printf("BAD\n");974 stdout.printf("BAD\n");
...@@ -985,7 +985,7 @@ pub fn main(args: [][]u8) %void => {...@@ -985,7 +985,7 @@ pub fn main(args: [][]u8) %void => {
985985
986 add_simple_case("memcpy and memset intrinsics", R"SOURCE(986 add_simple_case("memcpy and memset intrinsics", R"SOURCE(
987import "std.zig";987import "std.zig";
988pub fn main(args: [][]u8) %void => {988pub fn main(args: [][]u8) -> %void {
989 var foo : [20]u8;989 var foo : [20]u8;
990 var bar : [20]u8;990 var bar : [20]u8;
991991
...@@ -1005,10 +1005,10 @@ import "std.zig";...@@ -1005,10 +1005,10 @@ import "std.zig";
1005const z : @typeof(stdin_fileno) = 0;1005const z : @typeof(stdin_fileno) = 0;
1006const x : @typeof(y) = 1234;1006const x : @typeof(y) = 1234;
1007const y : u16 = 5678;1007const y : u16 = 5678;
1008pub fn main(args: [][]u8) %void => {1008pub fn main(args: [][]u8) -> %void {
1009 var x : i32 = print_ok(x);1009 var x : i32 = print_ok(x);
1010}1010}
1011fn print_ok(val: @typeof(x)) @typeof(foo) => {1011fn print_ok(val: @typeof(x)) -> @typeof(foo) {
1012 stdout.printf("OK\n");1012 stdout.printf("OK\n");
1013 return 0;1013 return 0;
1014}1014}
...@@ -1036,7 +1036,7 @@ enum Bar {...@@ -1036,7 +1036,7 @@ enum Bar {
1036 D,1036 D,
1037}1037}
10381038
1039pub fn main(args: [][]u8) %void => {1039pub fn main(args: [][]u8) -> %void {
1040 const foo1 = Foo.One(13);1040 const foo1 = Foo.One(13);
1041 const foo2 = Foo.Two(Point { .x = 1234, .y = 5678, });1041 const foo2 = Foo.Two(Point { .x = 1234, .y = 5678, });
1042 const bar = Bar.B;1042 const bar = Bar.B;
...@@ -1067,7 +1067,7 @@ pub fn main(args: [][]u8) %void => {...@@ -1067,7 +1067,7 @@ pub fn main(args: [][]u8) %void => {
1067 add_simple_case("array literal", R"SOURCE(1067 add_simple_case("array literal", R"SOURCE(
1068import "std.zig";1068import "std.zig";
10691069
1070pub fn main(args: [][]u8) %void => {1070pub fn main(args: [][]u8) -> %void {
1071 const HEX_MULT = []u16{4096, 256, 16, 1};1071 const HEX_MULT = []u16{4096, 256, 16, 1};
10721072
1073 if (HEX_MULT.len != 4) {1073 if (HEX_MULT.len != 4) {
...@@ -1085,7 +1085,7 @@ pub fn main(args: [][]u8) %void => {...@@ -1085,7 +1085,7 @@ pub fn main(args: [][]u8) %void => {
1085 add_simple_case("nested arrays", R"SOURCE(1085 add_simple_case("nested arrays", R"SOURCE(
1086import "std.zig";1086import "std.zig";
10871087
1088pub fn main(args: [][]u8) %void => {1088pub fn main(args: [][]u8) -> %void {
1089 const array_of_strings = [][]u8 {"hello", "this", "is", "my", "thing"};1089 const array_of_strings = [][]u8 {"hello", "this", "is", "my", "thing"};
1090 var i: @typeof(array_of_strings.len) = 0;1090 var i: @typeof(array_of_strings.len) = 0;
1091 while (i < array_of_strings.len) {1091 while (i < array_of_strings.len) {
...@@ -1099,7 +1099,7 @@ pub fn main(args: [][]u8) %void => {...@@ -1099,7 +1099,7 @@ pub fn main(args: [][]u8) %void => {
1099 add_simple_case("for loops", R"SOURCE(1099 add_simple_case("for loops", R"SOURCE(
1100import "std.zig";1100import "std.zig";
11011101
1102pub fn main(args: [][]u8) %void => {1102pub fn main(args: [][]u8) -> %void {
1103 const array = []u8 {9, 8, 7, 6};1103 const array = []u8 {9, 8, 7, 6};
1104 for (item, array) {1104 for (item, array) {
1105 stdout.print_u64(item);1105 stdout.print_u64(item);
...@@ -1124,7 +1124,7 @@ pub fn main(args: [][]u8) %void => {...@@ -1124,7 +1124,7 @@ pub fn main(args: [][]u8) %void => {
1124 add_simple_case("function pointers", R"SOURCE(1124 add_simple_case("function pointers", R"SOURCE(
1125import "std.zig";1125import "std.zig";
11261126
1127pub fn main(args: [][]u8) %void => {1127pub fn main(args: [][]u8) -> %void {
1128 const fns = []@typeof(fn1) { fn1, fn2, fn3, fn4, };1128 const fns = []@typeof(fn1) { fn1, fn2, fn3, fn4, };
1129 for (f, fns) {1129 for (f, fns) {
1130 stdout.print_u64(f());1130 stdout.print_u64(f());
...@@ -1132,10 +1132,10 @@ pub fn main(args: [][]u8) %void => {...@@ -1132,10 +1132,10 @@ pub fn main(args: [][]u8) %void => {
1132 }1132 }
1133}1133}
11341134
1135fn fn1() u32 => {5}1135fn fn1() -> u32 {5}
1136fn fn2() u32 => {6}1136fn fn2() -> u32 {6}
1137fn fn3() u32 => {7}1137fn fn3() -> u32 {7}
1138fn fn4() u32 => {8}1138fn fn4() -> u32 {8}
1139 )SOURCE", "5\n6\n7\n8\n");1139 )SOURCE", "5\n6\n7\n8\n");
11401140
1141 add_simple_case("switch statement", R"SOURCE(1141 add_simple_case("switch statement", R"SOURCE(
...@@ -1148,7 +1148,7 @@ enum Foo {...@@ -1148,7 +1148,7 @@ enum Foo {
1148 D,1148 D,
1149}1149}
11501150
1151pub fn main(args: [][]u8) %void => {1151pub fn main(args: [][]u8) -> %void {
1152 const foo = Foo.C;1152 const foo = Foo.C;
1153 const val: i32 = switch (foo) {1153 const val: i32 = switch (foo) {
1154 Foo.A => 1,1154 Foo.A => 1,
...@@ -1169,7 +1169,7 @@ import "std.zig";...@@ -1169,7 +1169,7 @@ import "std.zig";
11691169
1170const ten = 10;1170const ten = 10;
11711171
1172pub fn main(args: [][]u8) %void => {1172pub fn main(args: [][]u8) -> %void {
1173 const one = 1;1173 const one = 1;
1174 const eleven = ten + one;1174 const eleven = ten + one;
11751175
...@@ -1188,7 +1188,7 @@ struct Foo {...@@ -1188,7 +1188,7 @@ struct Foo {
1188 y: bool,1188 y: bool,
1189}1189}
1190var foo = Foo { .x = 13, .y = true, };1190var foo = Foo { .x = 13, .y = true, };
1191pub fn main(args: [][]u8) %void => {1191pub fn main(args: [][]u8) -> %void {
1192 foo.x += 1;1192 foo.x += 1;
1193 if (foo.x != 14) {1193 if (foo.x != 14) {
1194 stdout.printf("BAD\n");1194 stdout.printf("BAD\n");
...@@ -1201,7 +1201,7 @@ pub fn main(args: [][]u8) %void => {...@@ -1201,7 +1201,7 @@ pub fn main(args: [][]u8) %void => {
1201 add_simple_case("statically initialized array literal", R"SOURCE(1201 add_simple_case("statically initialized array literal", R"SOURCE(
1202import "std.zig";1202import "std.zig";
1203const x = []u8{1,2,3,4};1203const x = []u8{1,2,3,4};
1204pub fn main(args: [][]u8) %void => {1204pub fn main(args: [][]u8) -> %void {
1205 const y : [4]u8 = x;1205 const y : [4]u8 = x;
1206 if (y[3] != 4) {1206 if (y[3] != 4) {
1207 stdout.printf("BAD\n");1207 stdout.printf("BAD\n");
...@@ -1215,7 +1215,7 @@ pub fn main(args: [][]u8) %void => {...@@ -1215,7 +1215,7 @@ pub fn main(args: [][]u8) %void => {
1215import "std.zig";1215import "std.zig";
1216error err1;1216error err1;
1217error err2;1217error err2;
1218pub fn main(args: [][]u8) %void => {1218pub fn main(args: [][]u8) -> %void {
1219 const a = i32(error.err1);1219 const a = i32(error.err1);
1220 const b = i32(error.err2);1220 const b = i32(error.err2);
1221 if (a == b) {1221 if (a == b) {
...@@ -1228,7 +1228,7 @@ pub fn main(args: [][]u8) %void => {...@@ -1228,7 +1228,7 @@ pub fn main(args: [][]u8) %void => {
12281228
1229 add_simple_case("return with implicit cast from while loop", R"SOURCE(1229 add_simple_case("return with implicit cast from while loop", R"SOURCE(
1230import "std.zig";1230import "std.zig";
1231pub fn main(args: [][]u8) %void => {1231pub fn main(args: [][]u8) -> %void {
1232 while (true) {1232 while (true) {
1233 stdout.printf("OK\n");1233 stdout.printf("OK\n");
1234 return;1234 return;
...@@ -1242,13 +1242,13 @@ struct Foo {...@@ -1242,13 +1242,13 @@ struct Foo {
1242 x: i32,1242 x: i32,
1243 y: i32,1243 y: i32,
1244}1244}
1245fn make_foo(x: i32, y: i32) Foo => {1245fn make_foo(x: i32, y: i32) -> Foo {
1246 Foo {1246 Foo {
1247 .x = x,1247 .x = x,
1248 .y = y,1248 .y = y,
1249 }1249 }
1250}1250}
1251pub fn main(args: [][]u8) %void => {1251pub fn main(args: [][]u8) -> %void {
1252 const foo = make_foo(1234, 5678);1252 const foo = make_foo(1234, 5678);
1253 if (foo.y != 5678) {1253 if (foo.y != 5678) {
1254 stdout.printf("BAD\n");1254 stdout.printf("BAD\n");
...@@ -1260,14 +1260,14 @@ pub fn main(args: [][]u8) %void => {...@@ -1260,14 +1260,14 @@ pub fn main(args: [][]u8) %void => {
1260 add_simple_case("%% binary operator", R"SOURCE(1260 add_simple_case("%% binary operator", R"SOURCE(
1261import "std.zig";1261import "std.zig";
1262error ItBroke;1262error ItBroke;
1263fn g(x: bool) %isize => {1263fn g(x: bool) -> %isize {
1264 if (x) {1264 if (x) {
1265 error.ItBroke1265 error.ItBroke
1266 } else {1266 } else {
1267 101267 10
1268 }1268 }
1269}1269}
1270pub fn main(args: [][]u8) %void => {1270pub fn main(args: [][]u8) -> %void {
1271 const a = g(true) %% 3;1271 const a = g(true) %% 3;
1272 const b = g(false) %% 3;1272 const b = g(false) %% 3;
1273 if (a != 3) {1273 if (a != 3) {
...@@ -1286,8 +1286,8 @@ pub fn main(args: [][]u8) %void => {...@@ -1286,8 +1286,8 @@ pub fn main(args: [][]u8) %void => {
12861286
1287static void add_compile_failure_test_cases(void) {1287static void add_compile_failure_test_cases(void) {
1288 add_compile_fail_case("multiple function definitions", R"SOURCE(1288 add_compile_fail_case("multiple function definitions", R"SOURCE(
1289fn a() => {}1289fn a() {}
1290fn a() => {}1290fn a() {}
1291 )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'a'");1291 )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'a'");
12921292
1293 add_compile_fail_case("bad directive", R"SOURCE(1293 add_compile_fail_case("bad directive", R"SOURCE(
...@@ -1296,46 +1296,46 @@ extern {...@@ -1296,46 +1296,46 @@ extern {
1296 fn b();1296 fn b();
1297}1297}
1298#bogus2("")1298#bogus2("")
1299fn a() => {}1299fn a() {}
1300 )SOURCE", 2, ".tmp_source.zig:2:1: error: invalid directive: 'bogus1'",1300 )SOURCE", 2, ".tmp_source.zig:2:1: error: invalid directive: 'bogus1'",
1301 ".tmp_source.zig:6:1: error: invalid directive: 'bogus2'");1301 ".tmp_source.zig:6:1: error: invalid directive: 'bogus2'");
13021302
1303 add_compile_fail_case("unreachable with return", R"SOURCE(1303 add_compile_fail_case("unreachable with return", R"SOURCE(
1304fn a() unreachable => {return;}1304fn a() -> unreachable {return;}
1305 )SOURCE", 1, ".tmp_source.zig:2:24: error: expected type 'unreachable', got 'void'");1305 )SOURCE", 1, ".tmp_source.zig:2:24: error: expected type 'unreachable', got 'void'");
13061306
1307 add_compile_fail_case("control reaches end of non-void function", R"SOURCE(1307 add_compile_fail_case("control reaches end of non-void function", R"SOURCE(
1308fn a() i32 => {}1308fn a() -> i32 {}
1309 )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', got 'void'");1309 )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', got 'void'");
13101310
1311 add_compile_fail_case("undefined function call", R"SOURCE(1311 add_compile_fail_case("undefined function call", R"SOURCE(
1312fn a() => {1312fn a() {
1313 b();1313 b();
1314}1314}
1315 )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'");1315 )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'");
13161316
1317 add_compile_fail_case("wrong number of arguments", R"SOURCE(1317 add_compile_fail_case("wrong number of arguments", R"SOURCE(
1318fn a() => {1318fn a() {
1319 b(1);1319 b(1);
1320}1320}
1321fn b(a: i32, b: i32, c: i32) => { }1321fn b(a: i32, b: i32, c: i32) { }
1322 )SOURCE", 1, ".tmp_source.zig:3:6: error: expected 3 arguments, got 1");1322 )SOURCE", 1, ".tmp_source.zig:3:6: error: expected 3 arguments, got 1");
13231323
1324 add_compile_fail_case("invalid type", R"SOURCE(1324 add_compile_fail_case("invalid type", R"SOURCE(
1325fn a() bogus => {}1325fn a() -> bogus {}
1326 )SOURCE", 1, ".tmp_source.zig:2:8: error: use of undeclared identifier 'bogus'");1326 )SOURCE", 1, ".tmp_source.zig:2:11: error: use of undeclared identifier 'bogus'");
13271327
1328 add_compile_fail_case("pointer to unreachable", R"SOURCE(1328 add_compile_fail_case("pointer to unreachable", R"SOURCE(
1329fn a() &unreachable => {}1329fn a() -> &unreachable {}
1330 )SOURCE", 1, ".tmp_source.zig:2:8: error: pointer to unreachable not allowed");1330 )SOURCE", 1, ".tmp_source.zig:2:11: error: pointer to unreachable not allowed");
13311331
1332 add_compile_fail_case("unreachable code", R"SOURCE(1332 add_compile_fail_case("unreachable code", R"SOURCE(
1333fn a() => {1333fn a() {
1334 return;1334 return;
1335 b();1335 b();
1336}1336}
13371337
1338fn b() => {}1338fn b() {}
1339 )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code");1339 )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code");
13401340
1341 add_compile_fail_case("bad version string", R"SOURCE(1341 add_compile_fail_case("bad version string", R"SOURCE(
...@@ -1348,7 +1348,7 @@ import "bogus-does-not-exist.zig";...@@ -1348,7 +1348,7 @@ import "bogus-does-not-exist.zig";
1348 )SOURCE", 1, ".tmp_source.zig:2:1: error: unable to find 'bogus-does-not-exist.zig'");1348 )SOURCE", 1, ".tmp_source.zig:2:1: error: unable to find 'bogus-does-not-exist.zig'");
13491349
1350 add_compile_fail_case("undeclared identifier", R"SOURCE(1350 add_compile_fail_case("undeclared identifier", R"SOURCE(
1351fn a() => {1351fn a() {
1352 b +1352 b +
1353 c1353 c
1354}1354}
...@@ -1357,95 +1357,95 @@ fn a() => {...@@ -1357,95 +1357,95 @@ fn a() => {
1357 ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'");1357 ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'");
13581358
1359 add_compile_fail_case("goto cause unreachable code", R"SOURCE(1359 add_compile_fail_case("goto cause unreachable code", R"SOURCE(
1360fn a() => {1360fn a() {
1361 goto done;1361 goto done;
1362 b();1362 b();
1363done:1363done:
1364 return;1364 return;
1365}1365}
1366fn b() => {}1366fn b() {}
1367 )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code");1367 )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code");
13681368
1369 add_compile_fail_case("parameter redeclaration", R"SOURCE(1369 add_compile_fail_case("parameter redeclaration", R"SOURCE(
1370fn f(a : i32, a : i32) => {1370fn f(a : i32, a : i32) {
1371}1371}
1372 )SOURCE", 1, ".tmp_source.zig:2:15: error: redeclaration of variable 'a'");1372 )SOURCE", 1, ".tmp_source.zig:2:15: error: redeclaration of variable 'a'");
13731373
1374 add_compile_fail_case("local variable redeclaration", R"SOURCE(1374 add_compile_fail_case("local variable redeclaration", R"SOURCE(
1375fn f() => {1375fn f() {
1376 const a : i32 = 0;1376 const a : i32 = 0;
1377 const a = 0;1377 const a = 0;
1378}1378}
1379 )SOURCE", 1, ".tmp_source.zig:4:5: error: redeclaration of variable 'a'");1379 )SOURCE", 1, ".tmp_source.zig:4:5: error: redeclaration of variable 'a'");
13801380
1381 add_compile_fail_case("local variable redeclares parameter", R"SOURCE(1381 add_compile_fail_case("local variable redeclares parameter", R"SOURCE(
1382fn f(a : i32) => {1382fn f(a : i32) {
1383 const a = 0;1383 const a = 0;
1384}1384}
1385 )SOURCE", 1, ".tmp_source.zig:3:5: error: redeclaration of variable 'a'");1385 )SOURCE", 1, ".tmp_source.zig:3:5: error: redeclaration of variable 'a'");
13861386
1387 add_compile_fail_case("variable has wrong type", R"SOURCE(1387 add_compile_fail_case("variable has wrong type", R"SOURCE(
1388fn f() i32 => {1388fn f() -> i32 {
1389 const a = c"a";1389 const a = c"a";
1390 a1390 a
1391}1391}
1392 )SOURCE", 1, ".tmp_source.zig:4:5: error: expected type 'i32', got '&const u8'");1392 )SOURCE", 1, ".tmp_source.zig:4:5: error: expected type 'i32', got '&const u8'");
13931393
1394 add_compile_fail_case("if condition is bool, not int", R"SOURCE(1394 add_compile_fail_case("if condition is bool, not int", R"SOURCE(
1395fn f() => {1395fn f() {
1396 if (0) {}1396 if (0) {}
1397}1397}
1398 )SOURCE", 1, ".tmp_source.zig:3:9: error: value 0 cannot be represented in type 'bool'");1398 )SOURCE", 1, ".tmp_source.zig:3:9: error: value 0 cannot be represented in type 'bool'");
13991399
1400 add_compile_fail_case("assign unreachable", R"SOURCE(1400 add_compile_fail_case("assign unreachable", R"SOURCE(
1401fn f() => {1401fn f() {
1402 const a = return;1402 const a = return;
1403}1403}
1404 )SOURCE", 1, ".tmp_source.zig:3:5: error: variable initialization is unreachable");1404 )SOURCE", 1, ".tmp_source.zig:3:5: error: variable initialization is unreachable");
14051405
1406 add_compile_fail_case("unreachable variable", R"SOURCE(1406 add_compile_fail_case("unreachable variable", R"SOURCE(
1407fn f() => {1407fn f() {
1408 const a : unreachable = return;1408 const a : unreachable = return;
1409}1409}
1410 )SOURCE", 1, ".tmp_source.zig:3:15: error: variable of type 'unreachable' not allowed");1410 )SOURCE", 1, ".tmp_source.zig:3:15: error: variable of type 'unreachable' not allowed");
14111411
1412 add_compile_fail_case("unreachable parameter", R"SOURCE(1412 add_compile_fail_case("unreachable parameter", R"SOURCE(
1413fn f(a : unreachable) => {}1413fn f(a : unreachable) {}
1414 )SOURCE", 1, ".tmp_source.zig:2:10: error: parameter of type 'unreachable' not allowed");1414 )SOURCE", 1, ".tmp_source.zig:2:10: error: parameter of type 'unreachable' not allowed");
14151415
1416 add_compile_fail_case("unused label", R"SOURCE(1416 add_compile_fail_case("unused label", R"SOURCE(
1417fn f() => {1417fn f() {
1418a_label:1418a_label:
1419}1419}
1420 )SOURCE", 1, ".tmp_source.zig:3:1: error: label 'a_label' defined but not used");1420 )SOURCE", 1, ".tmp_source.zig:3:1: error: label 'a_label' defined but not used");
14211421
1422 add_compile_fail_case("bad assignment target", R"SOURCE(1422 add_compile_fail_case("bad assignment target", R"SOURCE(
1423fn f() => {1423fn f() {
1424 3 = 3;1424 3 = 3;
1425}1425}
1426 )SOURCE", 1, ".tmp_source.zig:3:5: error: invalid assignment target");1426 )SOURCE", 1, ".tmp_source.zig:3:5: error: invalid assignment target");
14271427
1428 add_compile_fail_case("assign to constant variable", R"SOURCE(1428 add_compile_fail_case("assign to constant variable", R"SOURCE(
1429fn f() => {1429fn f() {
1430 const a = 3;1430 const a = 3;
1431 a = 4;1431 a = 4;
1432}1432}
1433 )SOURCE", 1, ".tmp_source.zig:4:5: error: cannot assign to constant");1433 )SOURCE", 1, ".tmp_source.zig:4:5: error: cannot assign to constant");
14341434
1435 add_compile_fail_case("use of undeclared identifier", R"SOURCE(1435 add_compile_fail_case("use of undeclared identifier", R"SOURCE(
1436fn f() => {1436fn f() {
1437 b = 3;1437 b = 3;
1438}1438}
1439 )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'");1439 )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'");
14401440
1441 add_compile_fail_case("const is a statement, not an expression", R"SOURCE(1441 add_compile_fail_case("const is a statement, not an expression", R"SOURCE(
1442fn f() => {1442fn f() {
1443 (const a = 0);1443 (const a = 0);
1444}1444}
1445 )SOURCE", 1, ".tmp_source.zig:3:6: error: invalid token: 'const'");1445 )SOURCE", 1, ".tmp_source.zig:3:6: error: invalid token: 'const'");
14461446
1447 add_compile_fail_case("array access errors", R"SOURCE(1447 add_compile_fail_case("array access errors", R"SOURCE(
1448fn f() => {1448fn f() {
1449 var bad : bool;1449 var bad : bool;
1450 i[i] = i[i];1450 i[i] = i[i];
1451 bad[bad] = bad[bad];1451 bad[bad] = bad[bad];
...@@ -1460,19 +1460,19 @@ fn f() => {...@@ -1460,19 +1460,19 @@ fn f() => {
1460 ".tmp_source.zig:5:20: error: expected type 'isize', got 'bool'");1460 ".tmp_source.zig:5:20: error: expected type 'isize', got 'bool'");
14611461
1462 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(1462 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(
1463fn f(...) => {}1463fn f(...) {}
1464 )SOURCE", 1, ".tmp_source.zig:2:1: error: variadic arguments only allowed in extern functions");1464 )SOURCE", 1, ".tmp_source.zig:2:1: error: variadic arguments only allowed in extern functions");
14651465
1466 add_compile_fail_case("write to const global variable", R"SOURCE(1466 add_compile_fail_case("write to const global variable", R"SOURCE(
1467const x : i32 = 99;1467const x : i32 = 99;
1468fn f() => {1468fn f() {
1469 x = 1;1469 x = 1;
1470}1470}
1471 )SOURCE", 1, ".tmp_source.zig:4:5: error: cannot assign to constant");1471 )SOURCE", 1, ".tmp_source.zig:4:5: error: cannot assign to constant");
14721472
14731473
1474 add_compile_fail_case("missing else clause", R"SOURCE(1474 add_compile_fail_case("missing else clause", R"SOURCE(
1475fn f() => {1475fn f() {
1476 const x : i32 = if (true) { 1 };1476 const x : i32 = if (true) { 1 };
1477 const y = if (true) { i32(1) };1477 const y = if (true) { i32(1) };
1478}1478}
...@@ -1491,7 +1491,7 @@ struct C { a : A, }...@@ -1491,7 +1491,7 @@ struct C { a : A, }
14911491
1492 add_compile_fail_case("invalid struct field", R"SOURCE(1492 add_compile_fail_case("invalid struct field", R"SOURCE(
1493struct A { x : i32, }1493struct A { x : i32, }
1494fn f() => {1494fn f() {
1495 var a : A;1495 var a : A;
1496 a.foo = 1;1496 a.foo = 1;
1497 const y = a.bar;1497 const y = a.bar;
...@@ -1522,7 +1522,7 @@ var a : i32 = 2;...@@ -1522,7 +1522,7 @@ var a : i32 = 2;
15221522
1523 add_compile_fail_case("byvalue struct on exported functions", R"SOURCE(1523 add_compile_fail_case("byvalue struct on exported functions", R"SOURCE(
1524struct A { x : i32, }1524struct A { x : i32, }
1525export fn f(a : A) => {}1525export fn f(a : A) {}
1526 )SOURCE", 1, ".tmp_source.zig:3:13: error: byvalue struct parameters not yet supported on exported functions");1526 )SOURCE", 1, ".tmp_source.zig:3:13: error: byvalue struct parameters not yet supported on exported functions");
15271527
1528 add_compile_fail_case("duplicate field in struct value expression", R"SOURCE(1528 add_compile_fail_case("duplicate field in struct value expression", R"SOURCE(
...@@ -1531,7 +1531,7 @@ struct A {...@@ -1531,7 +1531,7 @@ struct A {
1531 y : i32,1531 y : i32,
1532 z : i32,1532 z : i32,
1533}1533}
1534fn f() => {1534fn f() {
1535 const a = A {1535 const a = A {
1536 .z = 1,1536 .z = 1,
1537 .y = 2,1537 .y = 2,
...@@ -1547,7 +1547,7 @@ struct A {...@@ -1547,7 +1547,7 @@ struct A {
1547 y : i32,1547 y : i32,
1548 z : i32,1548 z : i32,
1549}1549}
1550fn f() => {1550fn f() {
1551 // we want the error on the '{' not the 'A' because1551 // we want the error on the '{' not the 'A' because
1552 // the A could be a complicated expression1552 // the A could be a complicated expression
1553 const a = A {1553 const a = A {
...@@ -1563,7 +1563,7 @@ struct A {...@@ -1563,7 +1563,7 @@ struct A {
1563 y : i32,1563 y : i32,
1564 z : i32,1564 z : i32,
1565}1565}
1566fn f() => {1566fn f() {
1567 const a = A {1567 const a = A {
1568 .z = 4,1568 .z = 4,
1569 .y = 2,1569 .y = 2,
...@@ -1573,33 +1573,33 @@ fn f() => {...@@ -1573,33 +1573,33 @@ fn f() => {
1573 )SOURCE", 1, ".tmp_source.zig:11:9: error: no member named 'foo' in 'A'");1573 )SOURCE", 1, ".tmp_source.zig:11:9: error: no member named 'foo' in 'A'");
15741574
1575 add_compile_fail_case("invalid break expression", R"SOURCE(1575 add_compile_fail_case("invalid break expression", R"SOURCE(
1576fn f() => {1576fn f() {
1577 break;1577 break;
1578}1578}
1579 )SOURCE", 1, ".tmp_source.zig:3:5: error: 'break' expression outside loop");1579 )SOURCE", 1, ".tmp_source.zig:3:5: error: 'break' expression outside loop");
15801580
1581 add_compile_fail_case("invalid continue expression", R"SOURCE(1581 add_compile_fail_case("invalid continue expression", R"SOURCE(
1582fn f() => {1582fn f() {
1583 continue;1583 continue;
1584}1584}
1585 )SOURCE", 1, ".tmp_source.zig:3:5: error: 'continue' expression outside loop");1585 )SOURCE", 1, ".tmp_source.zig:3:5: error: 'continue' expression outside loop");
15861586
1587 add_compile_fail_case("invalid maybe type", R"SOURCE(1587 add_compile_fail_case("invalid maybe type", R"SOURCE(
1588fn f() => {1588fn f() {
1589 if (const x ?= true) { }1589 if (const x ?= true) { }
1590}1590}
1591 )SOURCE", 1, ".tmp_source.zig:3:20: error: expected maybe type");1591 )SOURCE", 1, ".tmp_source.zig:3:20: error: expected maybe type");
15921592
1593 add_compile_fail_case("cast unreachable", R"SOURCE(1593 add_compile_fail_case("cast unreachable", R"SOURCE(
1594fn f() i32 => {1594fn f() -> i32 {
1595 i32(return 1)1595 i32(return 1)
1596}1596}
1597 )SOURCE", 1, ".tmp_source.zig:3:8: error: invalid cast from type 'unreachable' to 'i32'");1597 )SOURCE", 1, ".tmp_source.zig:3:8: error: invalid cast from type 'unreachable' to 'i32'");
15981598
1599 add_compile_fail_case("invalid builtin fn", R"SOURCE(1599 add_compile_fail_case("invalid builtin fn", R"SOURCE(
1600fn f() @bogus(foo) => {1600fn f() -> @bogus(foo) {
1601}1601}
1602 )SOURCE", 1, ".tmp_source.zig:2:8: error: invalid builtin function: 'bogus'");1602 )SOURCE", 1, ".tmp_source.zig:2:11: error: invalid builtin function: 'bogus'");
16031603
1604 add_compile_fail_case("top level decl dependency loop", R"SOURCE(1604 add_compile_fail_case("top level decl dependency loop", R"SOURCE(
1605const a : @typeof(b) = 0;1605const a : @typeof(b) = 0;
...@@ -1607,7 +1607,7 @@ const b : @typeof(a) = 0;...@@ -1607,7 +1607,7 @@ const b : @typeof(a) = 0;
1607 )SOURCE", 1, ".tmp_source.zig:3:19: error: use of undeclared identifier 'a'");1607 )SOURCE", 1, ".tmp_source.zig:3:19: error: use of undeclared identifier 'a'");
16081608
1609 add_compile_fail_case("noalias on non pointer param", R"SOURCE(1609 add_compile_fail_case("noalias on non pointer param", R"SOURCE(
1610fn f(noalias x: i32) => {}1610fn f(noalias x: i32) {}
1611 )SOURCE", 1, ".tmp_source.zig:2:6: error: noalias on non-pointer parameter");1611 )SOURCE", 1, ".tmp_source.zig:2:6: error: noalias on non-pointer parameter");
16121612
1613 add_compile_fail_case("struct init syntax for array", R"SOURCE(1613 add_compile_fail_case("struct init syntax for array", R"SOURCE(
...@@ -1622,14 +1622,14 @@ var foo = u8;...@@ -1622,14 +1622,14 @@ var foo = u8;
1622struct Foo {}1622struct Foo {}
1623struct Bar {}1623struct Bar {}
16241624
1625fn f(Foo: i32) => {1625fn f(Foo: i32) {
1626 var Bar : i32;1626 var Bar : i32;
1627}1627}
1628 )SOURCE", 2, ".tmp_source.zig:5:6: error: variable shadows type 'Foo'",1628 )SOURCE", 2, ".tmp_source.zig:5:6: error: variable shadows type 'Foo'",
1629 ".tmp_source.zig:6:5: error: variable shadows type 'Bar'");1629 ".tmp_source.zig:6:5: error: variable shadows type 'Bar'");
16301630
1631 add_compile_fail_case("multiple else prongs in a switch", R"SOURCE(1631 add_compile_fail_case("multiple else prongs in a switch", R"SOURCE(
1632fn f() => {1632fn f() {
1633 const value: bool = switch (u32(111)) {1633 const value: bool = switch (u32(111)) {
1634 1234 => false,1634 1234 => false,
1635 else => true,1635 else => true,
...@@ -1640,7 +1640,7 @@ fn f() => {...@@ -1640,7 +1640,7 @@ fn f() => {
16401640
1641 add_compile_fail_case("global variable initializer must be constant expression", R"SOURCE(1641 add_compile_fail_case("global variable initializer must be constant expression", R"SOURCE(
1642extern {1642extern {
1643 fn foo() i32;1643 fn foo() -> i32;
1644}1644}
1645const x = foo();1645const x = foo();
1646 )SOURCE", 1, ".tmp_source.zig:5:11: error: global variable initializer requires constant expression");1646 )SOURCE", 1, ".tmp_source.zig:5:11: error: global variable initializer requires constant expression");