| ... | @@ -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") |
| 100 | extern { | 100 | extern { |
| 101 | fn puts(s: &const u8) i32; | 101 | fn puts(s: &const u8) -> i32; |
| 102 | } | 102 | } |
| 103 | | 103 | |
| 104 | export fn main(argc: i32, argv: &&u8) i32 => { | 104 | export 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 => { |
| 111 | import "std.zig"; | 111 | import "std.zig"; |
| 112 | import "syscall.zig"; | 112 | import "syscall.zig"; |
| 113 | | 113 | |
| 114 | fn empty_function_1() => {} | 114 | fn empty_function_1() {} |
| 115 | fn empty_function_2() => { return; } | 115 | fn empty_function_2() { return; } |
| 116 | | 116 | |
| 117 | pub fn main(args: [][]u8) %void => { | 117 | pub 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 | } |
| 122 | | 122 | |
| 123 | fn this_is_a_function() unreachable => { | 123 | fn 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 comment | 133 | * multi line doc comment |
| 134 | */ | 134 | */ |
| 135 | fn another_function() => {} | 135 | fn another_function() {} |
| 136 | | 136 | |
| 137 | /// this is a documentation comment | 137 | /// this is a documentation comment |
| 138 | /// doc comment line 2 | 138 | /// doc comment line 2 |
| 139 | pub fn main(args: [][]u8) %void => { | 139 | pub 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 => { |
| 146 | import "std.zig"; | 146 | import "std.zig"; |
| 147 | import "foo.zig"; | 147 | import "foo.zig"; |
| 148 | | 148 | |
| 149 | pub fn main(args: [][]u8) %void => { | 149 | pub 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 | } |
| 153 | | 153 | |
| 154 | fn private_function() => { | 154 | fn 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"; |
| 161 | | 161 | |
| 162 | // purposefully conflicting function with main.zig | 162 | // purposefully conflicting function with main.zig |
| 163 | // but it's private so it should be OK | 163 | // but it's private so it should be OK |
| 164 | fn private_function() => { | 164 | fn private_function() { |
| 165 | stdout.printf("OK 1\n"); | 165 | stdout.printf("OK 1\n"); |
| 166 | } | 166 | } |
| 167 | | 167 | |
| 168 | pub fn print_text() => { | 168 | pub 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() => { |
| 176 | import "foo.zig"; | 176 | import "foo.zig"; |
| 177 | import "bar.zig"; | 177 | import "bar.zig"; |
| 178 | | 178 | |
| 179 | pub fn main(args: [][]u8) %void => { | 179 | pub 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 => { |
| 184 | | 184 | |
| 185 | add_source_file(tc, "foo.zig", R"SOURCE( | 185 | add_source_file(tc, "foo.zig", R"SOURCE( |
| 186 | import "std.zig"; | 186 | import "std.zig"; |
| 187 | pub fn foo_function() => { | 187 | pub 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() => { |
| 193 | import "other.zig"; | 193 | import "other.zig"; |
| 194 | import "std.zig"; | 194 | import "std.zig"; |
| 195 | | 195 | |
| 196 | pub fn bar_function() => { | 196 | pub 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"); |
| 202 | | 202 | |
| 203 | add_source_file(tc, "other.zig", R"SOURCE( | 203 | add_source_file(tc, "other.zig", R"SOURCE( |
| 204 | pub fn foo_function() bool => { | 204 | pub fn foo_function() -> bool { |
| 205 | // this one conflicts with the one from foo | 205 | // 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( |
| 212 | import "std.zig"; | 212 | import "std.zig"; |
| 213 | | 213 | |
| 214 | pub fn main(args: [][]u8) %void => { | 214 | pub 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( |
| 232 | import "std.zig"; | 232 | import "std.zig"; |
| 233 | | 233 | |
| 234 | fn add(a: i32, b: i32) i32 => { | 234 | fn add(a: i32, b: i32) -> i32 { |
| 235 | a + b | 235 | a + b |
| 236 | } | 236 | } |
| 237 | | 237 | |
| 238 | pub fn main(args: [][]u8) %void => { | 238 | pub 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( |
| 246 | import "std.zig"; | 246 | import "std.zig"; |
| 247 | | 247 | |
| 248 | fn loop(a : i32) => { | 248 | fn 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 | } |
| 258 | | 258 | |
| 259 | pub fn main(args: [][]u8) %void => { | 259 | pub 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( |
| 265 | import "std.zig"; | 265 | import "std.zig"; |
| 266 | | 266 | |
| 267 | pub fn main(args: [][]u8) %void => { | 267 | pub 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( |
| 277 | import "std.zig"; | 277 | import "std.zig"; |
| 278 | | 278 | |
| 279 | pub fn main(args: [][]u8) %void => { | 279 | pub 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( |
| 288 | import "std.zig"; | 288 | import "std.zig"; |
| 289 | | 289 | |
| 290 | pub fn main(args: [][]u8) %void => { | 290 | pub 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( |
| 305 | import "std.zig"; | 305 | import "std.zig"; |
| 306 | | 306 | |
| 307 | pub fn main(args: [][]u8) %void => { | 307 | pub fn main(args: [][]u8) -> %void { |
| 308 | void_fun(1, void{}, 2); | 308 | void_fun(1, void{}, 2); |
| 309 | } | 309 | } |
| 310 | | 310 | |
| 311 | fn void_fun(a : i32, b : void, c : i32) => { | 311 | fn 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 | } |
| 326 | pub fn main(args: [][]u8) %void => { | 326 | pub 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( |
| 344 | import "std.zig"; | 344 | import "std.zig"; |
| 345 | | 345 | |
| 346 | pub fn main(args: [][]u8) %void => { | 346 | pub 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( |
| 362 | import "std.zig"; | 362 | import "std.zig"; |
| 363 | | 363 | |
| 364 | pub fn main(args: [][]u8) %void => { | 364 | pub 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"); } |
| 367 | | 367 | |
| ... | @@ -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( |
| 377 | import "std.zig"; | 377 | import "std.zig"; |
| 378 | | 378 | |
| 379 | pub fn main(args: [][]u8) %void => { | 379 | pub fn main(args: [][]u8) -> %void { |
| 380 | var array : [5]i32; | 380 | var array : [5]i32; |
| 381 | | 381 | |
| 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 | } |
| 404 | fn get_array_len(a: []i32) isize => { | 404 | fn get_array_len(a: []i32) -> isize { |
| 405 | a.len | 405 | 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( |
| 411 | import "std.zig"; | 411 | import "std.zig"; |
| 412 | | 412 | |
| 413 | pub fn main(args: [][]u8) %void => { | 413 | pub 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( |
| 420 | import "std.zig"; | 420 | import "std.zig"; |
| 421 | | 421 | |
| 422 | pub fn main(args: [][]u8) %void => { | 422 | pub 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( |
| 441 | import "std.zig"; | 441 | import "std.zig"; |
| 442 | | 442 | |
| 443 | pub fn main(args: [][]u8) %void => { | 443 | pub 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( |
| 462 | import "std.zig"; | 462 | import "std.zig"; |
| 463 | | 463 | |
| 464 | pub fn main(args: [][]u8) %void => { | 464 | pub 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") |
| 485 | extern { | 485 | extern { |
| 486 | fn printf(__format: &const u8, ...) i32; | 486 | fn printf(__format: &const u8, ...) -> i32; |
| 487 | } | 487 | } |
| 488 | | 488 | |
| 489 | export fn main(argc: i32, argv: &&u8) i32 => { | 489 | export fn main(argc: i32, argv: &&u8) -> i32 { |
| 490 | printf(c"\n"); | 490 | printf(c"\n"); |
| 491 | | 491 | |
| 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( |
| 613 | import "std.zig"; | 613 | import "std.zig"; |
| 614 | | 614 | |
| 615 | pub fn main(args: [][]u8) %void => { | 615 | pub 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 | } |
| 635 | fn test_foo(foo : Foo) => { | 635 | fn 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 | } |
| 640 | fn test_mutation(foo : &Foo) => { | 640 | fn test_mutation(foo : &Foo) { |
| 641 | foo.c = 100; | 641 | foo.c = 100; |
| 642 | } | 642 | } |
| 643 | struct Node { | 643 | struct Node { |
| ... | @@ -648,7 +648,7 @@ struct Node { | ... | @@ -648,7 +648,7 @@ struct Node { |
| 648 | struct Val { | 648 | struct Val { |
| 649 | x: i32, | 649 | x: i32, |
| 650 | } | 650 | } |
| 651 | fn test_point_to_self() => { | 651 | fn test_point_to_self() { |
| 652 | var root : Node; | 652 | var root : Node; |
| 653 | root.val.x = 1; | 653 | root.val.x = 1; |
| 654 | | 654 | |
| ... | @@ -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 | } |
| 665 | fn test_byval_assign() => { | 665 | fn test_byval_assign() { |
| 666 | var foo1 : Foo; | 666 | var foo1 : Foo; |
| 667 | var foo2 : Foo; | 667 | var foo2 : Foo; |
| 668 | | 668 | |
| ... | @@ -674,7 +674,7 @@ fn test_byval_assign() => { | ... | @@ -674,7 +674,7 @@ fn test_byval_assign() => { |
| 674 | | 674 | |
| 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 | } |
| 677 | fn test_initializer() => { | 677 | fn 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"; |
| 686 | const g1 : i32 = 1233 + 1; | 686 | const g1 : i32 = 1233 + 1; |
| 687 | var g2 : i32 = 0; | 687 | var g2 : i32 = 0; |
| 688 | | 688 | |
| 689 | pub fn main(args: [][]u8) %void => { | 689 | pub 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 => { |
| 696 | | 696 | |
| 697 | add_simple_case("while loop", R"SOURCE( | 697 | add_simple_case("while loop", R"SOURCE( |
| 698 | import "std.zig"; | 698 | import "std.zig"; |
| 699 | pub fn main(args: [][]u8) %void => { | 699 | pub 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 | } |
| 707 | fn g() i32 => { | 707 | fn g() -> i32 { |
| 708 | return f(); | 708 | return f(); |
| 709 | } | 709 | } |
| 710 | fn f() i32 => { | 710 | fn 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 => { |
| 716 | | 716 | |
| 717 | add_simple_case("continue and break", R"SOURCE( | 717 | add_simple_case("continue and break", R"SOURCE( |
| 718 | import "std.zig"; | 718 | import "std.zig"; |
| 719 | pub fn main(args: [][]u8) %void => { | 719 | pub 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 => { |
| 731 | | 731 | |
| 732 | add_simple_case("maybe type", R"SOURCE( | 732 | add_simple_case("maybe type", R"SOURCE( |
| 733 | import "std.zig"; | 733 | import "std.zig"; |
| 734 | pub fn main(args: [][]u8) %void => { | 734 | pub fn main(args: [][]u8) -> %void { |
| 735 | const x : ?bool = true; | 735 | const x : ?bool = true; |
| 736 | | 736 | |
| 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 => { |
| 764 | | 764 | |
| 765 | add_simple_case("implicit cast after unreachable", R"SOURCE( | 765 | add_simple_case("implicit cast after unreachable", R"SOURCE( |
| 766 | import "std.zig"; | 766 | import "std.zig"; |
| 767 | pub fn main(args: [][]u8) %void => { | 767 | pub 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 | } |
| 773 | fn inner() i32 => { 1234 } | 773 | fn inner() -> i32 { 1234 } |
| 774 | fn outer() isize => { | 774 | fn 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 => { |
| 780 | import "std.zig"; | 780 | import "std.zig"; |
| 781 | const x: u16 = 13; | 781 | const x: u16 = 13; |
| 782 | const z: @typeof(x) = 19; | 782 | const z: @typeof(x) = 19; |
| 783 | pub fn main(args: [][]u8) %void => { | 783 | pub 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 => { |
| 791 | import "std.zig"; | 791 | import "std.zig"; |
| 792 | struct Rand { | 792 | struct 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.seed | 795 | r.seed |
| 796 | } | 796 | } |
| 797 | } | 797 | } |
| 798 | pub fn main(args: [][]u8) %void => { | 798 | pub 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( |
| 808 | import "std.zig"; | 808 | import "std.zig"; |
| 809 | | 809 | |
| 810 | pub fn main(args: [][]u8) %void => { | 810 | pub fn main(args: [][]u8) -> %void { |
| 811 | var x = i32(3); | 811 | var x = i32(3); |
| 812 | const y = &x; | 812 | const y = &x; |
| 813 | | 813 | |
| ... | @@ -828,7 +828,7 @@ import "std.zig"; | ... | @@ -828,7 +828,7 @@ import "std.zig"; |
| 828 | | 828 | |
| 829 | const ARRAY_SIZE : i8 = 20; | 829 | const ARRAY_SIZE : i8 = 20; |
| 830 | | 830 | |
| 831 | pub fn main(args: [][]u8) %void => { | 831 | pub 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 => { |
| 837 | | 837 | |
| 838 | add_simple_case("@min_value() and @max_value()", R"SOURCE( | 838 | add_simple_case("@min_value() and @max_value()", R"SOURCE( |
| 839 | import "std.zig"; | 839 | import "std.zig"; |
| 840 | pub fn main(args: [][]u8) %void => { | 840 | pub 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 => { |
| 923 | | 923 | |
| 924 | add_simple_case("slicing", R"SOURCE( | 924 | add_simple_case("slicing", R"SOURCE( |
| 925 | import "std.zig"; | 925 | import "std.zig"; |
| 926 | pub fn main(args: [][]u8) %void => { | 926 | pub fn main(args: [][]u8) -> %void { |
| 927 | var array : [20]i32; | 927 | var array : [20]i32; |
| 928 | | 928 | |
| 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 => { |
| 950 | | 950 | |
| 951 | add_simple_case("else if expression", R"SOURCE( | 951 | add_simple_case("else if expression", R"SOURCE( |
| 952 | import "std.zig"; | 952 | import "std.zig"; |
| 953 | pub fn main(args: [][]u8) %void => { | 953 | pub 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 | } |
| 958 | fn f(c: u8) u8 => { | 958 | fn f(c: u8) -> u8 { |
| 959 | if (c == 0) { | 959 | if (c == 0) { |
| 960 | 0 | 960 | 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 => { |
| 968 | | 968 | |
| 969 | add_simple_case("overflow intrinsics", R"SOURCE( | 969 | add_simple_case("overflow intrinsics", R"SOURCE( |
| 970 | import "std.zig"; | 970 | import "std.zig"; |
| 971 | pub fn main(args: [][]u8) %void => { | 971 | pub 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 => { |
| 985 | | 985 | |
| 986 | add_simple_case("memcpy and memset intrinsics", R"SOURCE( | 986 | add_simple_case("memcpy and memset intrinsics", R"SOURCE( |
| 987 | import "std.zig"; | 987 | import "std.zig"; |
| 988 | pub fn main(args: [][]u8) %void => { | 988 | pub 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; |
| 991 | | 991 | |
| ... | @@ -1005,10 +1005,10 @@ import "std.zig"; | ... | @@ -1005,10 +1005,10 @@ import "std.zig"; |
| 1005 | const z : @typeof(stdin_fileno) = 0; | 1005 | const z : @typeof(stdin_fileno) = 0; |
| 1006 | const x : @typeof(y) = 1234; | 1006 | const x : @typeof(y) = 1234; |
| 1007 | const y : u16 = 5678; | 1007 | const y : u16 = 5678; |
| 1008 | pub fn main(args: [][]u8) %void => { | 1008 | pub fn main(args: [][]u8) -> %void { |
| 1009 | var x : i32 = print_ok(x); | 1009 | var x : i32 = print_ok(x); |
| 1010 | } | 1010 | } |
| 1011 | fn print_ok(val: @typeof(x)) @typeof(foo) => { | 1011 | fn 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 | } |
| 1038 | | 1038 | |
| 1039 | pub fn main(args: [][]u8) %void => { | 1039 | pub 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( |
| 1068 | import "std.zig"; | 1068 | import "std.zig"; |
| 1069 | | 1069 | |
| 1070 | pub fn main(args: [][]u8) %void => { | 1070 | pub fn main(args: [][]u8) -> %void { |
| 1071 | const HEX_MULT = []u16{4096, 256, 16, 1}; | 1071 | const HEX_MULT = []u16{4096, 256, 16, 1}; |
| 1072 | | 1072 | |
| 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( |
| 1086 | import "std.zig"; | 1086 | import "std.zig"; |
| 1087 | | 1087 | |
| 1088 | pub fn main(args: [][]u8) %void => { | 1088 | pub 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( |
| 1100 | import "std.zig"; | 1100 | import "std.zig"; |
| 1101 | | 1101 | |
| 1102 | pub fn main(args: [][]u8) %void => { | 1102 | pub 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( |
| 1125 | import "std.zig"; | 1125 | import "std.zig"; |
| 1126 | | 1126 | |
| 1127 | pub fn main(args: [][]u8) %void => { | 1127 | pub 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 | } |
| 1134 | | 1134 | |
| 1135 | fn fn1() u32 => {5} | 1135 | fn fn1() -> u32 {5} |
| 1136 | fn fn2() u32 => {6} | 1136 | fn fn2() -> u32 {6} |
| 1137 | fn fn3() u32 => {7} | 1137 | fn fn3() -> u32 {7} |
| 1138 | fn fn4() u32 => {8} | 1138 | fn fn4() -> u32 {8} |
| 1139 | )SOURCE", "5\n6\n7\n8\n"); | 1139 | )SOURCE", "5\n6\n7\n8\n"); |
| 1140 | | 1140 | |
| 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 | } |
| 1150 | | 1150 | |
| 1151 | pub fn main(args: [][]u8) %void => { | 1151 | pub 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"; |
| 1169 | | 1169 | |
| 1170 | const ten = 10; | 1170 | const ten = 10; |
| 1171 | | 1171 | |
| 1172 | pub fn main(args: [][]u8) %void => { | 1172 | pub fn main(args: [][]u8) -> %void { |
| 1173 | const one = 1; | 1173 | const one = 1; |
| 1174 | const eleven = ten + one; | 1174 | const eleven = ten + one; |
| 1175 | | 1175 | |
| ... | @@ -1188,7 +1188,7 @@ struct Foo { | ... | @@ -1188,7 +1188,7 @@ struct Foo { |
| 1188 | y: bool, | 1188 | y: bool, |
| 1189 | } | 1189 | } |
| 1190 | var foo = Foo { .x = 13, .y = true, }; | 1190 | var foo = Foo { .x = 13, .y = true, }; |
| 1191 | pub fn main(args: [][]u8) %void => { | 1191 | pub 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( |
| 1202 | import "std.zig"; | 1202 | import "std.zig"; |
| 1203 | const x = []u8{1,2,3,4}; | 1203 | const x = []u8{1,2,3,4}; |
| 1204 | pub fn main(args: [][]u8) %void => { | 1204 | pub 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 => { |
| 1215 | import "std.zig"; | 1215 | import "std.zig"; |
| 1216 | error err1; | 1216 | error err1; |
| 1217 | error err2; | 1217 | error err2; |
| 1218 | pub fn main(args: [][]u8) %void => { | 1218 | pub 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 => { |
| 1228 | | 1228 | |
| 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( |
| 1230 | import "std.zig"; | 1230 | import "std.zig"; |
| 1231 | pub fn main(args: [][]u8) %void => { | 1231 | pub 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 | } |
| 1245 | fn make_foo(x: i32, y: i32) Foo => { | 1245 | fn 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 | } |
| 1251 | pub fn main(args: [][]u8) %void => { | 1251 | pub 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( |
| 1261 | import "std.zig"; | 1261 | import "std.zig"; |
| 1262 | error ItBroke; | 1262 | error ItBroke; |
| 1263 | fn g(x: bool) %isize => { | 1263 | fn g(x: bool) -> %isize { |
| 1264 | if (x) { | 1264 | if (x) { |
| 1265 | error.ItBroke | 1265 | error.ItBroke |
| 1266 | } else { | 1266 | } else { |
| 1267 | 10 | 1267 | 10 |
| 1268 | } | 1268 | } |
| 1269 | } | 1269 | } |
| 1270 | pub fn main(args: [][]u8) %void => { | 1270 | pub 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 => { |
| 1286 | | 1286 | |
| 1287 | static void add_compile_failure_test_cases(void) { | 1287 | static 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( |
| 1289 | fn a() => {} | 1289 | fn a() {} |
| 1290 | fn a() => {} | 1290 | fn 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'"); |
| 1292 | | 1292 | |
| 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("") |
| 1299 | fn a() => {} | 1299 | fn 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'"); |
| 1302 | | 1302 | |
| 1303 | add_compile_fail_case("unreachable with return", R"SOURCE( | 1303 | add_compile_fail_case("unreachable with return", R"SOURCE( |
| 1304 | fn a() unreachable => {return;} | 1304 | fn 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'"); |
| 1306 | | 1306 | |
| 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( |
| 1308 | fn a() i32 => {} | 1308 | fn 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'"); |
| 1310 | | 1310 | |
| 1311 | add_compile_fail_case("undefined function call", R"SOURCE( | 1311 | add_compile_fail_case("undefined function call", R"SOURCE( |
| 1312 | fn a() => { | 1312 | fn 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'"); |
| 1316 | | 1316 | |
| 1317 | add_compile_fail_case("wrong number of arguments", R"SOURCE( | 1317 | add_compile_fail_case("wrong number of arguments", R"SOURCE( |
| 1318 | fn a() => { | 1318 | fn a() { |
| 1319 | b(1); | 1319 | b(1); |
| 1320 | } | 1320 | } |
| 1321 | fn b(a: i32, b: i32, c: i32) => { } | 1321 | fn 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"); |
| 1323 | | 1323 | |
| 1324 | add_compile_fail_case("invalid type", R"SOURCE( | 1324 | add_compile_fail_case("invalid type", R"SOURCE( |
| 1325 | fn a() bogus => {} | 1325 | fn 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'"); |
| 1327 | | 1327 | |
| 1328 | add_compile_fail_case("pointer to unreachable", R"SOURCE( | 1328 | add_compile_fail_case("pointer to unreachable", R"SOURCE( |
| 1329 | fn a() &unreachable => {} | 1329 | fn 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"); |
| 1331 | | 1331 | |
| 1332 | add_compile_fail_case("unreachable code", R"SOURCE( | 1332 | add_compile_fail_case("unreachable code", R"SOURCE( |
| 1333 | fn a() => { | 1333 | fn a() { |
| 1334 | return; | 1334 | return; |
| 1335 | b(); | 1335 | b(); |
| 1336 | } | 1336 | } |
| 1337 | | 1337 | |
| 1338 | fn b() => {} | 1338 | fn b() {} |
| 1339 | )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code"); | 1339 | )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code"); |
| 1340 | | 1340 | |
| 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'"); |
| 1349 | | 1349 | |
| 1350 | add_compile_fail_case("undeclared identifier", R"SOURCE( | 1350 | add_compile_fail_case("undeclared identifier", R"SOURCE( |
| 1351 | fn a() => { | 1351 | fn a() { |
| 1352 | b + | 1352 | b + |
| 1353 | c | 1353 | 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'"); |
| 1358 | | 1358 | |
| 1359 | add_compile_fail_case("goto cause unreachable code", R"SOURCE( | 1359 | add_compile_fail_case("goto cause unreachable code", R"SOURCE( |
| 1360 | fn a() => { | 1360 | fn a() { |
| 1361 | goto done; | 1361 | goto done; |
| 1362 | b(); | 1362 | b(); |
| 1363 | done: | 1363 | done: |
| 1364 | return; | 1364 | return; |
| 1365 | } | 1365 | } |
| 1366 | fn b() => {} | 1366 | fn b() {} |
| 1367 | )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code"); | 1367 | )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code"); |
| 1368 | | 1368 | |
| 1369 | add_compile_fail_case("parameter redeclaration", R"SOURCE( | 1369 | add_compile_fail_case("parameter redeclaration", R"SOURCE( |
| 1370 | fn f(a : i32, a : i32) => { | 1370 | fn 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'"); |
| 1373 | | 1373 | |
| 1374 | add_compile_fail_case("local variable redeclaration", R"SOURCE( | 1374 | add_compile_fail_case("local variable redeclaration", R"SOURCE( |
| 1375 | fn f() => { | 1375 | fn 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'"); |
| 1380 | | 1380 | |
| 1381 | add_compile_fail_case("local variable redeclares parameter", R"SOURCE( | 1381 | add_compile_fail_case("local variable redeclares parameter", R"SOURCE( |
| 1382 | fn f(a : i32) => { | 1382 | fn 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'"); |
| 1386 | | 1386 | |
| 1387 | add_compile_fail_case("variable has wrong type", R"SOURCE( | 1387 | add_compile_fail_case("variable has wrong type", R"SOURCE( |
| 1388 | fn f() i32 => { | 1388 | fn f() -> i32 { |
| 1389 | const a = c"a"; | 1389 | const a = c"a"; |
| 1390 | a | 1390 | 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'"); |
| 1393 | | 1393 | |
| 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( |
| 1395 | fn f() => { | 1395 | fn 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'"); |
| 1399 | | 1399 | |
| 1400 | add_compile_fail_case("assign unreachable", R"SOURCE( | 1400 | add_compile_fail_case("assign unreachable", R"SOURCE( |
| 1401 | fn f() => { | 1401 | fn 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"); |
| 1405 | | 1405 | |
| 1406 | add_compile_fail_case("unreachable variable", R"SOURCE( | 1406 | add_compile_fail_case("unreachable variable", R"SOURCE( |
| 1407 | fn f() => { | 1407 | fn 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"); |
| 1411 | | 1411 | |
| 1412 | add_compile_fail_case("unreachable parameter", R"SOURCE( | 1412 | add_compile_fail_case("unreachable parameter", R"SOURCE( |
| 1413 | fn f(a : unreachable) => {} | 1413 | fn 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"); |
| 1415 | | 1415 | |
| 1416 | add_compile_fail_case("unused label", R"SOURCE( | 1416 | add_compile_fail_case("unused label", R"SOURCE( |
| 1417 | fn f() => { | 1417 | fn f() { |
| 1418 | a_label: | 1418 | a_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"); |
| 1421 | | 1421 | |
| 1422 | add_compile_fail_case("bad assignment target", R"SOURCE( | 1422 | add_compile_fail_case("bad assignment target", R"SOURCE( |
| 1423 | fn f() => { | 1423 | fn 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"); |
| 1427 | | 1427 | |
| 1428 | add_compile_fail_case("assign to constant variable", R"SOURCE( | 1428 | add_compile_fail_case("assign to constant variable", R"SOURCE( |
| 1429 | fn f() => { | 1429 | fn 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"); |
| 1434 | | 1434 | |
| 1435 | add_compile_fail_case("use of undeclared identifier", R"SOURCE( | 1435 | add_compile_fail_case("use of undeclared identifier", R"SOURCE( |
| 1436 | fn f() => { | 1436 | fn 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'"); |
| 1440 | | 1440 | |
| 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( |
| 1442 | fn f() => { | 1442 | fn 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'"); |
| 1446 | | 1446 | |
| 1447 | add_compile_fail_case("array access errors", R"SOURCE( | 1447 | add_compile_fail_case("array access errors", R"SOURCE( |
| 1448 | fn f() => { | 1448 | fn 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'"); |
| 1461 | | 1461 | |
| 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( |
| 1463 | fn f(...) => {} | 1463 | fn 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"); |
| 1465 | | 1465 | |
| 1466 | add_compile_fail_case("write to const global variable", R"SOURCE( | 1466 | add_compile_fail_case("write to const global variable", R"SOURCE( |
| 1467 | const x : i32 = 99; | 1467 | const x : i32 = 99; |
| 1468 | fn f() => { | 1468 | fn 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"); |
| 1472 | | 1472 | |
| 1473 | | 1473 | |
| 1474 | add_compile_fail_case("missing else clause", R"SOURCE( | 1474 | add_compile_fail_case("missing else clause", R"SOURCE( |
| 1475 | fn f() => { | 1475 | fn 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, } |
| 1491 | | 1491 | |
| 1492 | add_compile_fail_case("invalid struct field", R"SOURCE( | 1492 | add_compile_fail_case("invalid struct field", R"SOURCE( |
| 1493 | struct A { x : i32, } | 1493 | struct A { x : i32, } |
| 1494 | fn f() => { | 1494 | fn 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; |
| 1522 | | 1522 | |
| 1523 | add_compile_fail_case("byvalue struct on exported functions", R"SOURCE( | 1523 | add_compile_fail_case("byvalue struct on exported functions", R"SOURCE( |
| 1524 | struct A { x : i32, } | 1524 | struct A { x : i32, } |
| 1525 | export fn f(a : A) => {} | 1525 | export 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"); |
| 1527 | | 1527 | |
| 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 | } |
| 1534 | fn f() => { | 1534 | fn 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 | } |
| 1550 | fn f() => { | 1550 | fn f() { |
| 1551 | // we want the error on the '{' not the 'A' because | 1551 | // we want the error on the '{' not the 'A' because |
| 1552 | // the A could be a complicated expression | 1552 | // 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 | } |
| 1566 | fn f() => { | 1566 | fn 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'"); |
| 1574 | | 1574 | |
| 1575 | add_compile_fail_case("invalid break expression", R"SOURCE( | 1575 | add_compile_fail_case("invalid break expression", R"SOURCE( |
| 1576 | fn f() => { | 1576 | fn 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"); |
| 1580 | | 1580 | |
| 1581 | add_compile_fail_case("invalid continue expression", R"SOURCE( | 1581 | add_compile_fail_case("invalid continue expression", R"SOURCE( |
| 1582 | fn f() => { | 1582 | fn 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"); |
| 1586 | | 1586 | |
| 1587 | add_compile_fail_case("invalid maybe type", R"SOURCE( | 1587 | add_compile_fail_case("invalid maybe type", R"SOURCE( |
| 1588 | fn f() => { | 1588 | fn 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"); |
| 1592 | | 1592 | |
| 1593 | add_compile_fail_case("cast unreachable", R"SOURCE( | 1593 | add_compile_fail_case("cast unreachable", R"SOURCE( |
| 1594 | fn f() i32 => { | 1594 | fn 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'"); |
| 1598 | | 1598 | |
| 1599 | add_compile_fail_case("invalid builtin fn", R"SOURCE( | 1599 | add_compile_fail_case("invalid builtin fn", R"SOURCE( |
| 1600 | fn f() @bogus(foo) => { | 1600 | fn 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'"); |
| 1603 | | 1603 | |
| 1604 | add_compile_fail_case("top level decl dependency loop", R"SOURCE( | 1604 | add_compile_fail_case("top level decl dependency loop", R"SOURCE( |
| 1605 | const a : @typeof(b) = 0; | 1605 | const 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'"); |
| 1608 | | 1608 | |
| 1609 | add_compile_fail_case("noalias on non pointer param", R"SOURCE( | 1609 | add_compile_fail_case("noalias on non pointer param", R"SOURCE( |
| 1610 | fn f(noalias x: i32) => {} | 1610 | fn 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"); |
| 1612 | | 1612 | |
| 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; |
| 1622 | struct Foo {} | 1622 | struct Foo {} |
| 1623 | struct Bar {} | 1623 | struct Bar {} |
| 1624 | | 1624 | |
| 1625 | fn f(Foo: i32) => { | 1625 | fn 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'"); |
| 1630 | | 1630 | |
| 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( |
| 1632 | fn f() => { | 1632 | fn 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() => { |
| 1640 | | 1640 | |
| 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( |
| 1642 | extern { | 1642 | extern { |
| 1643 | fn foo() i32; | 1643 | fn foo() -> i32; |
| 1644 | } | 1644 | } |
| 1645 | const x = foo(); | 1645 | const 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"); |