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" ";"
2323
2424ExternBlock : 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
2828Directive : "#" "Symbol" "(" "String" ")"
2929
......@@ -31,7 +31,7 @@ FnVisibleMod : "pub" | "export"
3131
3232FnDecl : FnProto ";"
3333
34FnDef : FnProto "=>" Block
34FnDef : FnProto Block
3535
3636ParamDeclList : "(" list(ParamDecl, ",") ")"
3737
example/guess_number/main.zig+1-1
......@@ -3,7 +3,7 @@ export executable "guess_number";
33import "std.zig";
44import "rand.zig";
55
6pub fn main(args: [][]u8) %void => {
6pub fn main(args: [][]u8) -> %void {
77 %%stderr.print_str("Welcome to the Guess Number Game in Zig.\n");
88
99 var seed : u32;
example/hello_world/hello.zig+1-1
......@@ -2,6 +2,6 @@ export executable "hello";
22
33import "std.zig";
44
5pub fn main(args: [][]u8) %void => {
5pub fn main(args: [][]u8) -> %void {
66 stdout.printf("Hello, world!\n");
77}
example/hello_world/hello_libc.zig+2-2
......@@ -2,10 +2,10 @@ export executable "hello";
22
33#link("c")
44extern {
5 fn printf(__format: &const u8, ...) i32;
5 fn printf(__format: &const u8, ...) -> i32;
66}
77
8export fn main(argc: i32, argv: &&u8) i32 => {
8export fn main(argc: i32, argv: &&u8) -> i32 {
99 printf(c"Hello, world!\n");
1010 return 0;
1111}
example/multiple_files/foo.zig+2-2
......@@ -2,10 +2,10 @@ import "std.zig";
22
33// purposefully conflicting function with main.zig
44// but it's private so it should be OK
5fn private_function() => {
5fn private_function() {
66 stdout.printf("OK 1\n");
77}
88
9pub fn print_text() => {
9pub fn print_text() {
1010 private_function();
1111}
example/multiple_files/main.zig+2-3
......@@ -3,12 +3,11 @@ export executable "test-multiple-files";
33import "std.zig";
44import "foo.zig";
55
6pub fn main(args: [][]u8) i32 => {
6pub fn main(args: [][]u8) -> %void {
77 private_function();
88 stdout.printf("OK 2\n");
9 return 0;
109}
1110
12fn private_function() => {
11fn private_function() {
1312 print_text();
1413}
example/shared_library/mathtest.zig+2-2
......@@ -1,10 +1,10 @@
11#version("2.0.0")
22export library "mathtest";
33
4export fn add(a: i32, b: i32) i32 => {
4export fn add(a: i32, b: i32) -> i32 {
55 a + b
66}
77
8export fn hang() unreachable => {
8export fn hang() -> unreachable {
99 while (true) { }
1010}
src/parser.cpp+6-5
......@@ -2675,7 +2675,7 @@ static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandato
26752675}
26762676
26772677/*
2678FnProto : many(Directive) option(FnVisibleMod) "fn" "Symbol" ParamDeclList option(PrefixOpExpression)
2678FnProto : many(Directive) option(FnVisibleMod) "fn" "Symbol" ParamDeclList option("->" PrefixOpExpression)
26792679*/
26802680static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mandatory) {
26812681 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
27272727 ast_parse_param_decl_list(pc, token_index, &node->data.fn_proto.params, &node->data.fn_proto.is_var_args);
27282728
27292729 Token *next_token = &pc->tokens->at(*token_index);
2730 node->data.fn_proto.return_type = ast_parse_prefix_op_expr(pc, token_index, false);
2731 if (!node->data.fn_proto.return_type) {
2730 if (next_token->id == TokenIdArrow) {
2731 *token_index += 1;
2732 node->data.fn_proto.return_type = ast_parse_prefix_op_expr(pc, token_index, false);
2733 } else {
27322734 node->data.fn_proto.return_type = ast_create_void_type_node(pc, next_token);
27332735 }
27342736
......@@ -2737,7 +2739,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand
27372739}
27382740
27392741/*
2740FnDef : FnProto token(FatArrow) Block
2742FnDef : FnProto Block
27412743*/
27422744static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandatory) {
27432745 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
27462748 AstNode *node = ast_create_node_with_node(pc, NodeTypeFnDef, fn_proto);
27472749
27482750 node->data.fn_def.fn_proto = fn_proto;
2749 ast_eat_token(pc, token_index, TokenIdFatArrow);
27502751 node->data.fn_def.body = ast_parse_block(pc, token_index, true);
27512752
27522753 normalize_parent_ptrs(node);
std/bootstrap.zig+3-3
......@@ -8,14 +8,14 @@ var argv: &&u8 = undefined;
88var env: &&u8 = undefined;
99
1010#attribute("naked")
11export fn _start() unreachable => {
11export fn _start() -> unreachable {
1212 argc = asm("mov (%%rsp), %[argc]": [argc] "=r" (-> isize));
1313 argv = asm("lea 0x8(%%rsp), %[argv]": [argv] "=r" (-> &&u8));
1414 env = asm("lea 0x10(%%rsp,%%rdi,8), %[env]": [env] "=r" (-> &&u8));
1515 call_main()
1616}
1717
18fn strlen(ptr: &const u8) isize => {
18fn strlen(ptr: &const u8) -> isize {
1919 var count: isize = 0;
2020 while (ptr[count] != 0) {
2121 count += 1;
......@@ -23,7 +23,7 @@ fn strlen(ptr: &const u8) isize => {
2323 return count;
2424}
2525
26fn call_main() unreachable => {
26fn call_main() -> unreachable {
2727 var args: [argc][]u8;
2828 for (arg, args, i) {
2929 const ptr = argv[i];
std/builtin.zig+2-2
......@@ -1,7 +1,7 @@
11// These functions are provided when not linking against libc because LLVM
22// 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 {
55 var index : @typeof(n) = 0;
66 while (index != n) {
77 dest[index] = c;
......@@ -10,7 +10,7 @@ export fn memset(dest: &u8, c: u8, n: isize) &u8 => {
1010 return dest;
1111}
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 {
1414 var index : @typeof(n) = 0;
1515 while (index != n) {
1616 dest[index] = src[index];
std/rand.zig+6-6
......@@ -7,7 +7,7 @@ pub struct Rand {
77 index: isize,
88
99 /// Get 32 bits of randomness.
10 pub fn get_u32(r: &Rand) u32 => {
10 pub fn get_u32(r: &Rand) -> u32 {
1111 if (r.index == 0) {
1212 r.generate_numbers();
1313 }
......@@ -24,7 +24,7 @@ pub struct Rand {
2424 }
2525
2626 /// Fill `buf` with randomness.
27 pub fn get_bytes(r: &Rand, buf: []u8) => {
27 pub fn get_bytes(r: &Rand, buf: []u8) {
2828 var bytes_left = r.get_bytes_aligned(buf);
2929 if (bytes_left > 0) {
3030 var rand_val_array : [@sizeof(u32)]u8;
......@@ -38,7 +38,7 @@ pub struct Rand {
3838
3939 /// Get a random unsigned integer with even distribution between `start`
4040 /// 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 {
4242 const range = end - start;
4343 const leftover = @max_value(u64) % range;
4444 const upper_bound = @max_value(u64) - leftover;
......@@ -53,7 +53,7 @@ pub struct Rand {
5353 }
5454 }
5555
56 fn generate_numbers(r: &Rand) => {
56 fn generate_numbers(r: &Rand) {
5757 for (item, r.array, i) {
5858 const y : u32 = (item & 0x80000000) + (r.array[(i + 1) % ARRAY_SIZE] & 0x7fffffff);
5959 const untempered : u32 = r.array[(i + 397) % ARRAY_SIZE] ^ (y >> 1);
......@@ -67,7 +67,7 @@ pub struct Rand {
6767 }
6868
6969 // 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 {
7171 var bytes_left = buf.len;
7272 while (bytes_left >= 4) {
7373 *((&u32)(&buf[buf.len - bytes_left])) = r.get_u32();
......@@ -78,7 +78,7 @@ pub struct Rand {
7878}
7979
8080/// Initialize random state with the given seed.
81pub fn rand_new(seed: u32) Rand => {
81pub fn rand_new(seed: u32) -> Rand {
8282 var r: Rand;
8383 r.index = 0;
8484 r.array[0] = seed;
std/std.zig+12-12
......@@ -50,7 +50,7 @@ pub struct OutStream {
5050 index: isize,
5151 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 {
5454 var src_bytes_left = str.len;
5555 var src_index: @typeof(str.len) = 0;
5656 const dest_space_left = os.buffer.len - os.index;
......@@ -72,13 +72,13 @@ pub struct OutStream {
7272
7373 /// Prints a byte buffer, flushes the buffer, then returns the number of
7474 /// 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 {
7676 const byte_count = %return os.print_str(str);
7777 %return os.flush();
7878 return byte_count;
7979 }
8080
81 pub fn print_u64(os: &OutStream, x: u64) %isize => {
81 pub fn print_u64(os: &OutStream, x: u64) -> %isize {
8282 if (os.index + max_u64_base10_digits >= os.buffer.len) {
8383 %return os.flush();
8484 }
......@@ -93,7 +93,7 @@ pub struct OutStream {
9393 }
9494
9595
96 pub fn print_i64(os: &OutStream, x: i64) %isize => {
96 pub fn print_i64(os: &OutStream, x: i64) -> %isize {
9797 if (os.index + max_u64_base10_digits >= os.buffer.len) {
9898 %return os.flush();
9999 }
......@@ -108,7 +108,7 @@ pub struct OutStream {
108108 }
109109
110110
111 pub fn flush(os: &OutStream) %void => {
111 pub fn flush(os: &OutStream) -> %void {
112112 const amt_written = write(os.fd, os.buffer.ptr, os.index);
113113 os.index = 0;
114114 if (amt_written < 0) {
......@@ -130,7 +130,7 @@ pub struct OutStream {
130130pub struct InStream {
131131 fd: isize,
132132
133 pub fn read(is: &InStream, buf: []u8) %isize => {
133 pub fn read(is: &InStream, buf: []u8) -> %isize {
134134 const amt_read = read(is.fd, buf.ptr, buf.len);
135135 if (amt_read < 0) {
136136 return switch (-amt_read) {
......@@ -146,7 +146,7 @@ pub struct InStream {
146146 }
147147}
148148
149pub fn os_get_random_bytes(buf: []u8) %void => {
149pub fn os_get_random_bytes(buf: []u8) -> %void {
150150 const amt_got = getrandom(buf.ptr, buf.len, 0);
151151 if (amt_got < 0) {
152152 return switch (-amt_got) {
......@@ -162,7 +162,7 @@ pub fn os_get_random_bytes(buf: []u8) %void => {
162162pub error InvalidChar;
163163pub error Overflow;
164164
165pub fn parse_u64(buf: []u8, radix: u8) %u64 => {
165pub fn parse_u64(buf: []u8, radix: u8) -> %u64 {
166166 var x : u64 = 0;
167167
168168 for (c, buf) {
......@@ -186,7 +186,7 @@ pub fn parse_u64(buf: []u8, radix: u8) %u64 => {
186186 return x;
187187}
188188
189fn char_to_digit(c: u8) u8 => {
189fn char_to_digit(c: u8) -> u8 {
190190 // TODO use switch with range
191191 if ('0' <= c && c <= '9') {
192192 c - '0'
......@@ -199,7 +199,7 @@ fn char_to_digit(c: u8) u8 => {
199199 }
200200}
201201
202fn buf_print_i64(out_buf: []u8, x: i64) isize => {
202fn buf_print_i64(out_buf: []u8, x: i64) -> isize {
203203 if (x < 0) {
204204 out_buf[0] = '-';
205205 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 => {
208208 }
209209}
210210
211fn buf_print_u64(out_buf: []u8, x: u64) isize => {
211fn buf_print_u64(out_buf: []u8, x: u64) -> isize {
212212 var buf: [max_u64_base10_digits]u8;
213213 var a = x;
214214 var index = buf.len;
......@@ -229,6 +229,6 @@ fn buf_print_u64(out_buf: []u8, x: u64) isize => {
229229 return len;
230230}
231231
232fn min_isize(x: isize, y: isize) isize => {
232fn min_isize(x: isize, y: isize) -> isize {
233233 if (x < y) x else y
234234}
std/syscall.zig+6-6
......@@ -3,33 +3,33 @@ const SYS_write = 1;
33const SYS_exit = 60;
44const SYS_getrandom = 318;
55
6fn syscall1(number: isize, arg1: isize) isize => {
6fn syscall1(number: isize, arg1: isize) -> isize {
77 asm volatile ("syscall"
88 : [ret] "={rax}" (-> isize)
99 : [number] "{rax}" (number), [arg1] "{rdi}" (arg1)
1010 : "rcx", "r11")
1111}
1212
13fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) isize => {
13fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> isize {
1414 asm volatile ("syscall"
1515 : [ret] "={rax}" (-> isize)
1616 : [number] "{rax}" (number), [arg1] "{rdi}" (arg1), [arg2] "{rsi}" (arg2), [arg3] "{rdx}" (arg3)
1717 : "rcx", "r11")
1818}
1919
20pub fn read(fd: isize, buf: &u8, count: isize) isize => {
20pub fn read(fd: isize, buf: &u8, count: isize) -> isize {
2121 syscall3(SYS_read, isize(fd), isize(buf), count)
2222}
2323
24pub fn write(fd: isize, buf: &const u8, count: isize) isize => {
24pub fn write(fd: isize, buf: &const u8, count: isize) -> isize {
2525 syscall3(SYS_write, isize(fd), isize(buf), count)
2626}
2727
28pub fn exit(status: i32) unreachable => {
28pub fn exit(status: i32) -> unreachable {
2929 syscall1(SYS_exit, isize(status));
3030 unreachable{}
3131}
3232
33pub fn getrandom(buf: &u8, count: isize, flags: u32) isize => {
33pub fn getrandom(buf: &u8, count: isize, flags: u32) -> isize {
3434 syscall3(SYS_getrandom, isize(buf), count, isize(flags))
3535}
test/run_tests.cpp+133-133
......@@ -98,10 +98,10 @@ static void add_compiling_test_cases(void) {
9898 add_simple_case("hello world with libc", R"SOURCE(
9999#link("c")
100100extern {
101 fn puts(s: &const u8) i32;
101 fn puts(s: &const u8) -> i32;
102102}
103103
104export fn main(argc: i32, argv: &&u8) i32 => {
104export fn main(argc: i32, argv: &&u8) -> i32 {
105105 puts(c"Hello, world!");
106106 return 0;
107107}
......@@ -111,16 +111,16 @@ export fn main(argc: i32, argv: &&u8) i32 => {
111111import "std.zig";
112112import "syscall.zig";
113113
114fn empty_function_1() => {}
115fn empty_function_2() => { return; }
114fn empty_function_1() {}
115fn empty_function_2() { return; }
116116
117pub fn main(args: [][]u8) %void => {
117pub fn main(args: [][]u8) -> %void {
118118 empty_function_1();
119119 empty_function_2();
120120 this_is_a_function();
121121}
122122
123fn this_is_a_function() unreachable => {
123fn this_is_a_function() -> unreachable {
124124 stdout.printf("OK\n");
125125 exit(0);
126126}
......@@ -132,11 +132,11 @@ import "std.zig";
132132/**
133133 * multi line doc comment
134134 */
135fn another_function() => {}
135fn another_function() {}
136136
137137/// this is a documentation comment
138138/// doc comment line 2
139pub fn main(args: [][]u8) %void => {
139pub fn main(args: [][]u8) -> %void {
140140 stdout.printf(/* mid-line comment /* nested */ */ "OK\n");
141141}
142142 )SOURCE", "OK\n");
......@@ -146,12 +146,12 @@ pub fn main(args: [][]u8) %void => {
146146import "std.zig";
147147import "foo.zig";
148148
149pub fn main(args: [][]u8) %void => {
149pub fn main(args: [][]u8) -> %void {
150150 private_function();
151151 stdout.printf("OK 2\n");
152152}
153153
154fn private_function() => {
154fn private_function() {
155155 print_text();
156156}
157157 )SOURCE", "OK 1\nOK 2\n");
......@@ -161,11 +161,11 @@ import "std.zig";
161161
162162// purposefully conflicting function with main.zig
163163// but it's private so it should be OK
164fn private_function() => {
164fn private_function() {
165165 stdout.printf("OK 1\n");
166166}
167167
168pub fn print_text() => {
168pub fn print_text() {
169169 private_function();
170170}
171171 )SOURCE");
......@@ -176,7 +176,7 @@ pub fn print_text() => {
176176import "foo.zig";
177177import "bar.zig";
178178
179pub fn main(args: [][]u8) %void => {
179pub fn main(args: [][]u8) -> %void {
180180 foo_function();
181181 bar_function();
182182}
......@@ -184,7 +184,7 @@ pub fn main(args: [][]u8) %void => {
184184
185185 add_source_file(tc, "foo.zig", R"SOURCE(
186186import "std.zig";
187pub fn foo_function() => {
187pub fn foo_function() {
188188 stdout.printf("OK\n");
189189}
190190 )SOURCE");
......@@ -193,7 +193,7 @@ pub fn foo_function() => {
193193import "other.zig";
194194import "std.zig";
195195
196pub fn bar_function() => {
196pub fn bar_function() {
197197 if (foo_function()) {
198198 stdout.printf("OK\n");
199199 }
......@@ -201,7 +201,7 @@ pub fn bar_function() => {
201201 )SOURCE");
202202
203203 add_source_file(tc, "other.zig", R"SOURCE(
204pub fn foo_function() bool => {
204pub fn foo_function() -> bool {
205205 // this one conflicts with the one from foo
206206 return true;
207207}
......@@ -211,7 +211,7 @@ pub fn foo_function() bool => {
211211 add_simple_case("if statements", R"SOURCE(
212212import "std.zig";
213213
214pub fn main(args: [][]u8) %void => {
214pub fn main(args: [][]u8) -> %void {
215215 if (1 != 0) {
216216 stdout.printf("1 is true\n");
217217 } else {
......@@ -231,11 +231,11 @@ pub fn main(args: [][]u8) %void => {
231231 add_simple_case("params", R"SOURCE(
232232import "std.zig";
233233
234fn add(a: i32, b: i32) i32 => {
234fn add(a: i32, b: i32) -> i32 {
235235 a + b
236236}
237237
238pub fn main(args: [][]u8) %void => {
238pub fn main(args: [][]u8) -> %void {
239239 if (add(22, 11) == 33) {
240240 stdout.printf("pass\n");
241241 }
......@@ -245,7 +245,7 @@ pub fn main(args: [][]u8) %void => {
245245 add_simple_case("goto", R"SOURCE(
246246import "std.zig";
247247
248fn loop(a : i32) => {
248fn loop(a : i32) {
249249 if (a == 0) {
250250 goto done;
251251 }
......@@ -256,7 +256,7 @@ done:
256256 return;
257257}
258258
259pub fn main(args: [][]u8) %void => {
259pub fn main(args: [][]u8) -> %void {
260260 loop(3);
261261}
262262 )SOURCE", "loop\nloop\nloop\n");
......@@ -264,7 +264,7 @@ pub fn main(args: [][]u8) %void => {
264264 add_simple_case("local variables", R"SOURCE(
265265import "std.zig";
266266
267pub fn main(args: [][]u8) %void => {
267pub fn main(args: [][]u8) -> %void {
268268 const a : i32 = 1;
269269 const b = i32(2);
270270 if (a + b == 3) {
......@@ -276,7 +276,7 @@ pub fn main(args: [][]u8) %void => {
276276 add_simple_case("bool literals", R"SOURCE(
277277import "std.zig";
278278
279pub fn main(args: [][]u8) %void => {
279pub fn main(args: [][]u8) -> %void {
280280 if (true) { stdout.printf("OK 1\n"); }
281281 if (false) { stdout.printf("BAD 1\n"); }
282282 if (!true) { stdout.printf("BAD 2\n"); }
......@@ -287,7 +287,7 @@ pub fn main(args: [][]u8) %void => {
287287 add_simple_case("separate block scopes", R"SOURCE(
288288import "std.zig";
289289
290pub fn main(args: [][]u8) %void => {
290pub fn main(args: [][]u8) -> %void {
291291 if (true) {
292292 const no_conflict : i32 = 5;
293293 if (no_conflict == 5) { stdout.printf("OK 1\n"); }
......@@ -304,11 +304,11 @@ pub fn main(args: [][]u8) %void => {
304304 add_simple_case("void parameters", R"SOURCE(
305305import "std.zig";
306306
307pub fn main(args: [][]u8) %void => {
307pub fn main(args: [][]u8) -> %void {
308308 void_fun(1, void{}, 2);
309309}
310310
311fn void_fun(a : i32, b : void, c : i32) => {
311fn void_fun(a : i32, b : void, c : i32) {
312312 const v = b;
313313 const vv : void = if (a == 1) {v} else {};
314314 if (a + c == 3) { stdout.printf("OK\n"); }
......@@ -323,7 +323,7 @@ struct Foo {
323323 b : i32,
324324 c : void,
325325}
326pub fn main(args: [][]u8) %void => {
326pub fn main(args: [][]u8) -> %void {
327327 const foo = Foo {
328328 .a = void{},
329329 .b = 1,
......@@ -343,7 +343,7 @@ pub fn main(args: [][]u8) %void => {
343343 add_simple_case("void arrays", R"SOURCE(
344344import "std.zig";
345345
346pub fn main(args: [][]u8) %void => {
346pub fn main(args: [][]u8) -> %void {
347347 var array: [4]void;
348348 array[0] = void{};
349349 array[1] = array[2];
......@@ -361,7 +361,7 @@ pub fn main(args: [][]u8) %void => {
361361 add_simple_case("mutable local variables", R"SOURCE(
362362import "std.zig";
363363
364pub fn main(args: [][]u8) %void => {
364pub fn main(args: [][]u8) -> %void {
365365 var zero : i32 = 0;
366366 if (zero == 0) { stdout.printf("zero\n"); }
367367
......@@ -376,7 +376,7 @@ pub fn main(args: [][]u8) %void => {
376376 add_simple_case("arrays", R"SOURCE(
377377import "std.zig";
378378
379pub fn main(args: [][]u8) %void => {
379pub fn main(args: [][]u8) -> %void {
380380 var array : [5]i32;
381381
382382 var i : i32 = 0;
......@@ -401,7 +401,7 @@ pub fn main(args: [][]u8) %void => {
401401 stdout.printf("BAD\n");
402402 }
403403}
404fn get_array_len(a: []i32) isize => {
404fn get_array_len(a: []i32) -> isize {
405405 a.len
406406}
407407 )SOURCE", "OK\n");
......@@ -410,7 +410,7 @@ fn get_array_len(a: []i32) isize => {
410410 add_simple_case("hello world without libc", R"SOURCE(
411411import "std.zig";
412412
413pub fn main(args: [][]u8) %void => {
413pub fn main(args: [][]u8) -> %void {
414414 stdout.printf("Hello, world!\n");
415415}
416416 )SOURCE", "Hello, world!\n");
......@@ -419,7 +419,7 @@ pub fn main(args: [][]u8) %void => {
419419 add_simple_case("a + b + c", R"SOURCE(
420420import "std.zig";
421421
422pub fn main(args: [][]u8) %void => {
422pub fn main(args: [][]u8) -> %void {
423423 if (false || false || false) { stdout.printf("BAD 1\n"); }
424424 if (true && true && false) { stdout.printf("BAD 2\n"); }
425425 if (1 | 2 | 4 != 7) { stdout.printf("BAD 3\n"); }
......@@ -440,7 +440,7 @@ pub fn main(args: [][]u8) %void => {
440440 add_simple_case("short circuit", R"SOURCE(
441441import "std.zig";
442442
443pub fn main(args: [][]u8) %void => {
443pub fn main(args: [][]u8) -> %void {
444444 if (true || { stdout.printf("BAD 1\n"); false }) {
445445 stdout.printf("OK 1\n");
446446 }
......@@ -461,7 +461,7 @@ pub fn main(args: [][]u8) %void => {
461461 add_simple_case("modify operators", R"SOURCE(
462462import "std.zig";
463463
464pub fn main(args: [][]u8) %void => {
464pub fn main(args: [][]u8) -> %void {
465465 var i : i32 = 0;
466466 i += 5; if (i != 5) { stdout.printf("BAD +=\n"); }
467467 i -= 2; if (i != 3) { stdout.printf("BAD -=\n"); }
......@@ -483,10 +483,10 @@ pub fn main(args: [][]u8) %void => {
483483 add_simple_case("number literals", R"SOURCE(
484484#link("c")
485485extern {
486 fn printf(__format: &const u8, ...) i32;
486 fn printf(__format: &const u8, ...) -> i32;
487487}
488488
489export fn main(argc: i32, argv: &&u8) i32 => {
489export fn main(argc: i32, argv: &&u8) -> i32 {
490490 printf(c"\n");
491491
492492 printf(c"0: %llu\n",
......@@ -612,7 +612,7 @@ export fn main(argc: i32, argv: &&u8) i32 => {
612612 add_simple_case("structs", R"SOURCE(
613613import "std.zig";
614614
615pub fn main(args: [][]u8) %void => {
615pub fn main(args: [][]u8) -> %void {
616616 var foo : Foo;
617617 @memset(&foo, 0, @sizeof(Foo));
618618 foo.a += 1;
......@@ -632,12 +632,12 @@ struct Foo {
632632 b : bool,
633633 c : f32,
634634}
635fn test_foo(foo : Foo) => {
635fn test_foo(foo : Foo) {
636636 if (!foo.b) {
637637 stdout.printf("BAD\n");
638638 }
639639}
640fn test_mutation(foo : &Foo) => {
640fn test_mutation(foo : &Foo) {
641641 foo.c = 100;
642642}
643643struct Node {
......@@ -648,7 +648,7 @@ struct Node {
648648struct Val {
649649 x: i32,
650650}
651fn test_point_to_self() => {
651fn test_point_to_self() {
652652 var root : Node;
653653 root.val.x = 1;
654654
......@@ -662,7 +662,7 @@ fn test_point_to_self() => {
662662 stdout.printf("BAD\n");
663663 }
664664}
665fn test_byval_assign() => {
665fn test_byval_assign() {
666666 var foo1 : Foo;
667667 var foo2 : Foo;
668668
......@@ -674,7 +674,7 @@ fn test_byval_assign() => {
674674
675675 if (foo2.a != 1234) { stdout.printf("BAD - byval assignment failed\n"); }
676676}
677fn test_initializer() => {
677fn test_initializer() {
678678 const val = Val { .x = 42 };
679679 if (val.x != 42) { stdout.printf("BAD\n"); }
680680}
......@@ -686,7 +686,7 @@ import "std.zig";
686686const g1 : i32 = 1233 + 1;
687687var g2 : i32 = 0;
688688
689pub fn main(args: [][]u8) %void => {
689pub fn main(args: [][]u8) -> %void {
690690 if (g2 != 0) { stdout.printf("BAD\n"); }
691691 g2 = g1;
692692 if (g2 != 1234) { stdout.printf("BAD\n"); }
......@@ -696,7 +696,7 @@ pub fn main(args: [][]u8) %void => {
696696
697697 add_simple_case("while loop", R"SOURCE(
698698import "std.zig";
699pub fn main(args: [][]u8) %void => {
699pub fn main(args: [][]u8) -> %void {
700700 var i : i32 = 0;
701701 while (i < 4) {
702702 stdout.printf("loop\n");
......@@ -704,10 +704,10 @@ pub fn main(args: [][]u8) %void => {
704704 }
705705 g();
706706}
707fn g() i32 => {
707fn g() -> i32 {
708708 return f();
709709}
710fn f() i32 => {
710fn f() -> i32 {
711711 while (true) {
712712 return 0;
713713 }
......@@ -716,7 +716,7 @@ fn f() i32 => {
716716
717717 add_simple_case("continue and break", R"SOURCE(
718718import "std.zig";
719pub fn main(args: [][]u8) %void => {
719pub fn main(args: [][]u8) -> %void {
720720 var i : i32 = 0;
721721 while (true) {
722722 stdout.printf("loop\n");
......@@ -731,7 +731,7 @@ pub fn main(args: [][]u8) %void => {
731731
732732 add_simple_case("maybe type", R"SOURCE(
733733import "std.zig";
734pub fn main(args: [][]u8) %void => {
734pub fn main(args: [][]u8) -> %void {
735735 const x : ?bool = true;
736736
737737 if (const y ?= x) {
......@@ -764,14 +764,14 @@ pub fn main(args: [][]u8) %void => {
764764
765765 add_simple_case("implicit cast after unreachable", R"SOURCE(
766766import "std.zig";
767pub fn main(args: [][]u8) %void => {
767pub fn main(args: [][]u8) -> %void {
768768 const x = outer();
769769 if (x == 1234) {
770770 stdout.printf("OK\n");
771771 }
772772}
773fn inner() i32 => { 1234 }
774fn outer() isize => {
773fn inner() -> i32 { 1234 }
774fn outer() -> isize {
775775 return inner();
776776}
777777 )SOURCE", "OK\n");
......@@ -780,7 +780,7 @@ fn outer() isize => {
780780import "std.zig";
781781const x: u16 = 13;
782782const z: @typeof(x) = 19;
783pub fn main(args: [][]u8) %void => {
783pub fn main(args: [][]u8) -> %void {
784784 const y: @typeof(x) = 120;
785785 stdout.print_u64(@sizeof(@typeof(y)));
786786 stdout.printf("\n");
......@@ -791,11 +791,11 @@ pub fn main(args: [][]u8) %void => {
791791import "std.zig";
792792struct Rand {
793793 seed: u32,
794 pub fn get_seed(r: Rand) u32 => {
794 pub fn get_seed(r: Rand) -> u32 {
795795 r.seed
796796 }
797797}
798pub fn main(args: [][]u8) %void => {
798pub fn main(args: [][]u8) -> %void {
799799 const r = Rand {.seed = 1234};
800800 if (r.get_seed() != 1234) {
801801 stdout.printf("BAD seed\n");
......@@ -807,7 +807,7 @@ pub fn main(args: [][]u8) %void => {
807807 add_simple_case("pointer dereferencing", R"SOURCE(
808808import "std.zig";
809809
810pub fn main(args: [][]u8) %void => {
810pub fn main(args: [][]u8) -> %void {
811811 var x = i32(3);
812812 const y = &x;
813813
......@@ -828,7 +828,7 @@ import "std.zig";
828828
829829const ARRAY_SIZE : i8 = 20;
830830
831pub fn main(args: [][]u8) %void => {
831pub fn main(args: [][]u8) -> %void {
832832 var array : [ARRAY_SIZE]u8;
833833 stdout.print_u64(@sizeof(@typeof(array)));
834834 stdout.printf("\n");
......@@ -837,7 +837,7 @@ pub fn main(args: [][]u8) %void => {
837837
838838 add_simple_case("@min_value() and @max_value()", R"SOURCE(
839839import "std.zig";
840pub fn main(args: [][]u8) %void => {
840pub fn main(args: [][]u8) -> %void {
841841 stdout.printf("max u8: ");
842842 stdout.print_u64(@max_value(u8));
843843 stdout.printf("\n");
......@@ -923,7 +923,7 @@ pub fn main(args: [][]u8) %void => {
923923
924924 add_simple_case("slicing", R"SOURCE(
925925import "std.zig";
926pub fn main(args: [][]u8) %void => {
926pub fn main(args: [][]u8) -> %void {
927927 var array : [20]i32;
928928
929929 array[5] = 1234;
......@@ -950,12 +950,12 @@ pub fn main(args: [][]u8) %void => {
950950
951951 add_simple_case("else if expression", R"SOURCE(
952952import "std.zig";
953pub fn main(args: [][]u8) %void => {
953pub fn main(args: [][]u8) -> %void {
954954 if (f(1) == 1) {
955955 stdout.printf("OK\n");
956956 }
957957}
958fn f(c: u8) u8 => {
958fn f(c: u8) -> u8 {
959959 if (c == 0) {
960960 0
961961 } else if (c == 1) {
......@@ -968,7 +968,7 @@ fn f(c: u8) u8 => {
968968
969969 add_simple_case("overflow intrinsics", R"SOURCE(
970970import "std.zig";
971pub fn main(args: [][]u8) %void => {
971pub fn main(args: [][]u8) -> %void {
972972 var result: u8;
973973 if (!@add_with_overflow(u8, 250, 100, &result)) {
974974 stdout.printf("BAD\n");
......@@ -985,7 +985,7 @@ pub fn main(args: [][]u8) %void => {
985985
986986 add_simple_case("memcpy and memset intrinsics", R"SOURCE(
987987import "std.zig";
988pub fn main(args: [][]u8) %void => {
988pub fn main(args: [][]u8) -> %void {
989989 var foo : [20]u8;
990990 var bar : [20]u8;
991991
......@@ -1005,10 +1005,10 @@ import "std.zig";
10051005const z : @typeof(stdin_fileno) = 0;
10061006const x : @typeof(y) = 1234;
10071007const y : u16 = 5678;
1008pub fn main(args: [][]u8) %void => {
1008pub fn main(args: [][]u8) -> %void {
10091009 var x : i32 = print_ok(x);
10101010}
1011fn print_ok(val: @typeof(x)) @typeof(foo) => {
1011fn print_ok(val: @typeof(x)) -> @typeof(foo) {
10121012 stdout.printf("OK\n");
10131013 return 0;
10141014}
......@@ -1036,7 +1036,7 @@ enum Bar {
10361036 D,
10371037}
10381038
1039pub fn main(args: [][]u8) %void => {
1039pub fn main(args: [][]u8) -> %void {
10401040 const foo1 = Foo.One(13);
10411041 const foo2 = Foo.Two(Point { .x = 1234, .y = 5678, });
10421042 const bar = Bar.B;
......@@ -1067,7 +1067,7 @@ pub fn main(args: [][]u8) %void => {
10671067 add_simple_case("array literal", R"SOURCE(
10681068import "std.zig";
10691069
1070pub fn main(args: [][]u8) %void => {
1070pub fn main(args: [][]u8) -> %void {
10711071 const HEX_MULT = []u16{4096, 256, 16, 1};
10721072
10731073 if (HEX_MULT.len != 4) {
......@@ -1085,7 +1085,7 @@ pub fn main(args: [][]u8) %void => {
10851085 add_simple_case("nested arrays", R"SOURCE(
10861086import "std.zig";
10871087
1088pub fn main(args: [][]u8) %void => {
1088pub fn main(args: [][]u8) -> %void {
10891089 const array_of_strings = [][]u8 {"hello", "this", "is", "my", "thing"};
10901090 var i: @typeof(array_of_strings.len) = 0;
10911091 while (i < array_of_strings.len) {
......@@ -1099,7 +1099,7 @@ pub fn main(args: [][]u8) %void => {
10991099 add_simple_case("for loops", R"SOURCE(
11001100import "std.zig";
11011101
1102pub fn main(args: [][]u8) %void => {
1102pub fn main(args: [][]u8) -> %void {
11031103 const array = []u8 {9, 8, 7, 6};
11041104 for (item, array) {
11051105 stdout.print_u64(item);
......@@ -1124,7 +1124,7 @@ pub fn main(args: [][]u8) %void => {
11241124 add_simple_case("function pointers", R"SOURCE(
11251125import "std.zig";
11261126
1127pub fn main(args: [][]u8) %void => {
1127pub fn main(args: [][]u8) -> %void {
11281128 const fns = []@typeof(fn1) { fn1, fn2, fn3, fn4, };
11291129 for (f, fns) {
11301130 stdout.print_u64(f());
......@@ -1132,10 +1132,10 @@ pub fn main(args: [][]u8) %void => {
11321132 }
11331133}
11341134
1135fn fn1() u32 => {5}
1136fn fn2() u32 => {6}
1137fn fn3() u32 => {7}
1138fn fn4() u32 => {8}
1135fn fn1() -> u32 {5}
1136fn fn2() -> u32 {6}
1137fn fn3() -> u32 {7}
1138fn fn4() -> u32 {8}
11391139 )SOURCE", "5\n6\n7\n8\n");
11401140
11411141 add_simple_case("switch statement", R"SOURCE(
......@@ -1148,7 +1148,7 @@ enum Foo {
11481148 D,
11491149}
11501150
1151pub fn main(args: [][]u8) %void => {
1151pub fn main(args: [][]u8) -> %void {
11521152 const foo = Foo.C;
11531153 const val: i32 = switch (foo) {
11541154 Foo.A => 1,
......@@ -1169,7 +1169,7 @@ import "std.zig";
11691169
11701170const ten = 10;
11711171
1172pub fn main(args: [][]u8) %void => {
1172pub fn main(args: [][]u8) -> %void {
11731173 const one = 1;
11741174 const eleven = ten + one;
11751175
......@@ -1188,7 +1188,7 @@ struct Foo {
11881188 y: bool,
11891189}
11901190var foo = Foo { .x = 13, .y = true, };
1191pub fn main(args: [][]u8) %void => {
1191pub fn main(args: [][]u8) -> %void {
11921192 foo.x += 1;
11931193 if (foo.x != 14) {
11941194 stdout.printf("BAD\n");
......@@ -1201,7 +1201,7 @@ pub fn main(args: [][]u8) %void => {
12011201 add_simple_case("statically initialized array literal", R"SOURCE(
12021202import "std.zig";
12031203const x = []u8{1,2,3,4};
1204pub fn main(args: [][]u8) %void => {
1204pub fn main(args: [][]u8) -> %void {
12051205 const y : [4]u8 = x;
12061206 if (y[3] != 4) {
12071207 stdout.printf("BAD\n");
......@@ -1215,7 +1215,7 @@ pub fn main(args: [][]u8) %void => {
12151215import "std.zig";
12161216error err1;
12171217error err2;
1218pub fn main(args: [][]u8) %void => {
1218pub fn main(args: [][]u8) -> %void {
12191219 const a = i32(error.err1);
12201220 const b = i32(error.err2);
12211221 if (a == b) {
......@@ -1228,7 +1228,7 @@ pub fn main(args: [][]u8) %void => {
12281228
12291229 add_simple_case("return with implicit cast from while loop", R"SOURCE(
12301230import "std.zig";
1231pub fn main(args: [][]u8) %void => {
1231pub fn main(args: [][]u8) -> %void {
12321232 while (true) {
12331233 stdout.printf("OK\n");
12341234 return;
......@@ -1242,13 +1242,13 @@ struct Foo {
12421242 x: i32,
12431243 y: i32,
12441244}
1245fn make_foo(x: i32, y: i32) Foo => {
1245fn make_foo(x: i32, y: i32) -> Foo {
12461246 Foo {
12471247 .x = x,
12481248 .y = y,
12491249 }
12501250}
1251pub fn main(args: [][]u8) %void => {
1251pub fn main(args: [][]u8) -> %void {
12521252 const foo = make_foo(1234, 5678);
12531253 if (foo.y != 5678) {
12541254 stdout.printf("BAD\n");
......@@ -1260,14 +1260,14 @@ pub fn main(args: [][]u8) %void => {
12601260 add_simple_case("%% binary operator", R"SOURCE(
12611261import "std.zig";
12621262error ItBroke;
1263fn g(x: bool) %isize => {
1263fn g(x: bool) -> %isize {
12641264 if (x) {
12651265 error.ItBroke
12661266 } else {
12671267 10
12681268 }
12691269}
1270pub fn main(args: [][]u8) %void => {
1270pub fn main(args: [][]u8) -> %void {
12711271 const a = g(true) %% 3;
12721272 const b = g(false) %% 3;
12731273 if (a != 3) {
......@@ -1286,8 +1286,8 @@ pub fn main(args: [][]u8) %void => {
12861286
12871287static void add_compile_failure_test_cases(void) {
12881288 add_compile_fail_case("multiple function definitions", R"SOURCE(
1289fn a() => {}
1290fn a() => {}
1289fn a() {}
1290fn a() {}
12911291 )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'a'");
12921292
12931293 add_compile_fail_case("bad directive", R"SOURCE(
......@@ -1296,46 +1296,46 @@ extern {
12961296 fn b();
12971297}
12981298#bogus2("")
1299fn a() => {}
1299fn a() {}
13001300 )SOURCE", 2, ".tmp_source.zig:2:1: error: invalid directive: 'bogus1'",
13011301 ".tmp_source.zig:6:1: error: invalid directive: 'bogus2'");
13021302
13031303 add_compile_fail_case("unreachable with return", R"SOURCE(
1304fn a() unreachable => {return;}
1304fn a() -> unreachable {return;}
13051305 )SOURCE", 1, ".tmp_source.zig:2:24: error: expected type 'unreachable', got 'void'");
13061306
13071307 add_compile_fail_case("control reaches end of non-void function", R"SOURCE(
1308fn a() i32 => {}
1308fn a() -> i32 {}
13091309 )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', got 'void'");
13101310
13111311 add_compile_fail_case("undefined function call", R"SOURCE(
1312fn a() => {
1312fn a() {
13131313 b();
13141314}
13151315 )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'");
13161316
13171317 add_compile_fail_case("wrong number of arguments", R"SOURCE(
1318fn a() => {
1318fn a() {
13191319 b(1);
13201320}
1321fn b(a: i32, b: i32, c: i32) => { }
1321fn b(a: i32, b: i32, c: i32) { }
13221322 )SOURCE", 1, ".tmp_source.zig:3:6: error: expected 3 arguments, got 1");
13231323
13241324 add_compile_fail_case("invalid type", R"SOURCE(
1325fn a() bogus => {}
1326 )SOURCE", 1, ".tmp_source.zig:2:8: error: use of undeclared identifier 'bogus'");
1325fn a() -> bogus {}
1326 )SOURCE", 1, ".tmp_source.zig:2:11: error: use of undeclared identifier 'bogus'");
13271327
13281328 add_compile_fail_case("pointer to unreachable", R"SOURCE(
1329fn a() &unreachable => {}
1330 )SOURCE", 1, ".tmp_source.zig:2:8: error: pointer to unreachable not allowed");
1329fn a() -> &unreachable {}
1330 )SOURCE", 1, ".tmp_source.zig:2:11: error: pointer to unreachable not allowed");
13311331
13321332 add_compile_fail_case("unreachable code", R"SOURCE(
1333fn a() => {
1333fn a() {
13341334 return;
13351335 b();
13361336}
13371337
1338fn b() => {}
1338fn b() {}
13391339 )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code");
13401340
13411341 add_compile_fail_case("bad version string", R"SOURCE(
......@@ -1348,7 +1348,7 @@ import "bogus-does-not-exist.zig";
13481348 )SOURCE", 1, ".tmp_source.zig:2:1: error: unable to find 'bogus-does-not-exist.zig'");
13491349
13501350 add_compile_fail_case("undeclared identifier", R"SOURCE(
1351fn a() => {
1351fn a() {
13521352 b +
13531353 c
13541354}
......@@ -1357,95 +1357,95 @@ fn a() => {
13571357 ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'");
13581358
13591359 add_compile_fail_case("goto cause unreachable code", R"SOURCE(
1360fn a() => {
1360fn a() {
13611361 goto done;
13621362 b();
13631363done:
13641364 return;
13651365}
1366fn b() => {}
1366fn b() {}
13671367 )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code");
13681368
13691369 add_compile_fail_case("parameter redeclaration", R"SOURCE(
1370fn f(a : i32, a : i32) => {
1370fn f(a : i32, a : i32) {
13711371}
13721372 )SOURCE", 1, ".tmp_source.zig:2:15: error: redeclaration of variable 'a'");
13731373
13741374 add_compile_fail_case("local variable redeclaration", R"SOURCE(
1375fn f() => {
1375fn f() {
13761376 const a : i32 = 0;
13771377 const a = 0;
13781378}
13791379 )SOURCE", 1, ".tmp_source.zig:4:5: error: redeclaration of variable 'a'");
13801380
13811381 add_compile_fail_case("local variable redeclares parameter", R"SOURCE(
1382fn f(a : i32) => {
1382fn f(a : i32) {
13831383 const a = 0;
13841384}
13851385 )SOURCE", 1, ".tmp_source.zig:3:5: error: redeclaration of variable 'a'");
13861386
13871387 add_compile_fail_case("variable has wrong type", R"SOURCE(
1388fn f() i32 => {
1388fn f() -> i32 {
13891389 const a = c"a";
13901390 a
13911391}
13921392 )SOURCE", 1, ".tmp_source.zig:4:5: error: expected type 'i32', got '&const u8'");
13931393
13941394 add_compile_fail_case("if condition is bool, not int", R"SOURCE(
1395fn f() => {
1395fn f() {
13961396 if (0) {}
13971397}
13981398 )SOURCE", 1, ".tmp_source.zig:3:9: error: value 0 cannot be represented in type 'bool'");
13991399
14001400 add_compile_fail_case("assign unreachable", R"SOURCE(
1401fn f() => {
1401fn f() {
14021402 const a = return;
14031403}
14041404 )SOURCE", 1, ".tmp_source.zig:3:5: error: variable initialization is unreachable");
14051405
14061406 add_compile_fail_case("unreachable variable", R"SOURCE(
1407fn f() => {
1407fn f() {
14081408 const a : unreachable = return;
14091409}
14101410 )SOURCE", 1, ".tmp_source.zig:3:15: error: variable of type 'unreachable' not allowed");
14111411
14121412 add_compile_fail_case("unreachable parameter", R"SOURCE(
1413fn f(a : unreachable) => {}
1413fn f(a : unreachable) {}
14141414 )SOURCE", 1, ".tmp_source.zig:2:10: error: parameter of type 'unreachable' not allowed");
14151415
14161416 add_compile_fail_case("unused label", R"SOURCE(
1417fn f() => {
1417fn f() {
14181418a_label:
14191419}
14201420 )SOURCE", 1, ".tmp_source.zig:3:1: error: label 'a_label' defined but not used");
14211421
14221422 add_compile_fail_case("bad assignment target", R"SOURCE(
1423fn f() => {
1423fn f() {
14241424 3 = 3;
14251425}
14261426 )SOURCE", 1, ".tmp_source.zig:3:5: error: invalid assignment target");
14271427
14281428 add_compile_fail_case("assign to constant variable", R"SOURCE(
1429fn f() => {
1429fn f() {
14301430 const a = 3;
14311431 a = 4;
14321432}
14331433 )SOURCE", 1, ".tmp_source.zig:4:5: error: cannot assign to constant");
14341434
14351435 add_compile_fail_case("use of undeclared identifier", R"SOURCE(
1436fn f() => {
1436fn f() {
14371437 b = 3;
14381438}
14391439 )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'");
14401440
14411441 add_compile_fail_case("const is a statement, not an expression", R"SOURCE(
1442fn f() => {
1442fn f() {
14431443 (const a = 0);
14441444}
14451445 )SOURCE", 1, ".tmp_source.zig:3:6: error: invalid token: 'const'");
14461446
14471447 add_compile_fail_case("array access errors", R"SOURCE(
1448fn f() => {
1448fn f() {
14491449 var bad : bool;
14501450 i[i] = i[i];
14511451 bad[bad] = bad[bad];
......@@ -1460,19 +1460,19 @@ fn f() => {
14601460 ".tmp_source.zig:5:20: error: expected type 'isize', got 'bool'");
14611461
14621462 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(
1463fn f(...) => {}
1463fn f(...) {}
14641464 )SOURCE", 1, ".tmp_source.zig:2:1: error: variadic arguments only allowed in extern functions");
14651465
14661466 add_compile_fail_case("write to const global variable", R"SOURCE(
14671467const x : i32 = 99;
1468fn f() => {
1468fn f() {
14691469 x = 1;
14701470}
14711471 )SOURCE", 1, ".tmp_source.zig:4:5: error: cannot assign to constant");
14721472
14731473
14741474 add_compile_fail_case("missing else clause", R"SOURCE(
1475fn f() => {
1475fn f() {
14761476 const x : i32 = if (true) { 1 };
14771477 const y = if (true) { i32(1) };
14781478}
......@@ -1491,7 +1491,7 @@ struct C { a : A, }
14911491
14921492 add_compile_fail_case("invalid struct field", R"SOURCE(
14931493struct A { x : i32, }
1494fn f() => {
1494fn f() {
14951495 var a : A;
14961496 a.foo = 1;
14971497 const y = a.bar;
......@@ -1522,7 +1522,7 @@ var a : i32 = 2;
15221522
15231523 add_compile_fail_case("byvalue struct on exported functions", R"SOURCE(
15241524struct A { x : i32, }
1525export fn f(a : A) => {}
1525export fn f(a : A) {}
15261526 )SOURCE", 1, ".tmp_source.zig:3:13: error: byvalue struct parameters not yet supported on exported functions");
15271527
15281528 add_compile_fail_case("duplicate field in struct value expression", R"SOURCE(
......@@ -1531,7 +1531,7 @@ struct A {
15311531 y : i32,
15321532 z : i32,
15331533}
1534fn f() => {
1534fn f() {
15351535 const a = A {
15361536 .z = 1,
15371537 .y = 2,
......@@ -1547,7 +1547,7 @@ struct A {
15471547 y : i32,
15481548 z : i32,
15491549}
1550fn f() => {
1550fn f() {
15511551 // we want the error on the '{' not the 'A' because
15521552 // the A could be a complicated expression
15531553 const a = A {
......@@ -1563,7 +1563,7 @@ struct A {
15631563 y : i32,
15641564 z : i32,
15651565}
1566fn f() => {
1566fn f() {
15671567 const a = A {
15681568 .z = 4,
15691569 .y = 2,
......@@ -1573,33 +1573,33 @@ fn f() => {
15731573 )SOURCE", 1, ".tmp_source.zig:11:9: error: no member named 'foo' in 'A'");
15741574
15751575 add_compile_fail_case("invalid break expression", R"SOURCE(
1576fn f() => {
1576fn f() {
15771577 break;
15781578}
15791579 )SOURCE", 1, ".tmp_source.zig:3:5: error: 'break' expression outside loop");
15801580
15811581 add_compile_fail_case("invalid continue expression", R"SOURCE(
1582fn f() => {
1582fn f() {
15831583 continue;
15841584}
15851585 )SOURCE", 1, ".tmp_source.zig:3:5: error: 'continue' expression outside loop");
15861586
15871587 add_compile_fail_case("invalid maybe type", R"SOURCE(
1588fn f() => {
1588fn f() {
15891589 if (const x ?= true) { }
15901590}
15911591 )SOURCE", 1, ".tmp_source.zig:3:20: error: expected maybe type");
15921592
15931593 add_compile_fail_case("cast unreachable", R"SOURCE(
1594fn f() i32 => {
1594fn f() -> i32 {
15951595 i32(return 1)
15961596}
15971597 )SOURCE", 1, ".tmp_source.zig:3:8: error: invalid cast from type 'unreachable' to 'i32'");
15981598
15991599 add_compile_fail_case("invalid builtin fn", R"SOURCE(
1600fn f() @bogus(foo) => {
1600fn f() -> @bogus(foo) {
16011601}
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
16041604 add_compile_fail_case("top level decl dependency loop", R"SOURCE(
16051605const a : @typeof(b) = 0;
......@@ -1607,7 +1607,7 @@ const b : @typeof(a) = 0;
16071607 )SOURCE", 1, ".tmp_source.zig:3:19: error: use of undeclared identifier 'a'");
16081608
16091609 add_compile_fail_case("noalias on non pointer param", R"SOURCE(
1610fn f(noalias x: i32) => {}
1610fn f(noalias x: i32) {}
16111611 )SOURCE", 1, ".tmp_source.zig:2:6: error: noalias on non-pointer parameter");
16121612
16131613 add_compile_fail_case("struct init syntax for array", R"SOURCE(
......@@ -1622,14 +1622,14 @@ var foo = u8;
16221622struct Foo {}
16231623struct Bar {}
16241624
1625fn f(Foo: i32) => {
1625fn f(Foo: i32) {
16261626 var Bar : i32;
16271627}
16281628 )SOURCE", 2, ".tmp_source.zig:5:6: error: variable shadows type 'Foo'",
16291629 ".tmp_source.zig:6:5: error: variable shadows type 'Bar'");
16301630
16311631 add_compile_fail_case("multiple else prongs in a switch", R"SOURCE(
1632fn f() => {
1632fn f() {
16331633 const value: bool = switch (u32(111)) {
16341634 1234 => false,
16351635 else => true,
......@@ -1640,7 +1640,7 @@ fn f() => {
16401640
16411641 add_compile_fail_case("global variable initializer must be constant expression", R"SOURCE(
16421642extern {
1643 fn foo() i32;
1643 fn foo() -> i32;
16441644}
16451645const x = foo();
16461646 )SOURCE", 1, ".tmp_source.zig:5:11: error: global variable initializer requires constant expression");