| ... | ... | @@ -98,10 +98,10 @@ static void add_compiling_test_cases(void) { |
| 98 | 98 | add_simple_case("hello world with libc", R"SOURCE( |
| 99 | 99 | #link("c") |
| 100 | 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 | 105 | puts(c"Hello, world!"); |
| 106 | 106 | return 0; |
| 107 | 107 | } |
| ... | ... | @@ -111,16 +111,16 @@ export fn main(argc: i32, argv: &&u8) i32 => { |
| 111 | 111 | import "std.zig"; |
| 112 | 112 | import "syscall.zig"; |
| 113 | 113 | |
| 114 | | fn empty_function_1() => {} |
| 115 | | fn empty_function_2() => { return; } |
| 114 | fn empty_function_1() {} |
| 115 | fn empty_function_2() { return; } |
| 116 | 116 | |
| 117 | | pub fn main(args: [][]u8) %void => { |
| 117 | pub fn main(args: [][]u8) -> %void { |
| 118 | 118 | empty_function_1(); |
| 119 | 119 | empty_function_2(); |
| 120 | 120 | this_is_a_function(); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | | fn this_is_a_function() unreachable => { |
| 123 | fn this_is_a_function() -> unreachable { |
| 124 | 124 | stdout.printf("OK\n"); |
| 125 | 125 | exit(0); |
| 126 | 126 | } |
| ... | ... | @@ -132,11 +132,11 @@ import "std.zig"; |
| 132 | 132 | /** |
| 133 | 133 | * multi line doc comment |
| 134 | 134 | */ |
| 135 | | fn another_function() => {} |
| 135 | fn another_function() {} |
| 136 | 136 | |
| 137 | 137 | /// this is a documentation comment |
| 138 | 138 | /// doc comment line 2 |
| 139 | | pub fn main(args: [][]u8) %void => { |
| 139 | pub fn main(args: [][]u8) -> %void { |
| 140 | 140 | stdout.printf(/* mid-line comment /* nested */ */ "OK\n"); |
| 141 | 141 | } |
| 142 | 142 | )SOURCE", "OK\n"); |
| ... | ... | @@ -146,12 +146,12 @@ pub fn main(args: [][]u8) %void => { |
| 146 | 146 | import "std.zig"; |
| 147 | 147 | import "foo.zig"; |
| 148 | 148 | |
| 149 | | pub fn main(args: [][]u8) %void => { |
| 149 | pub fn main(args: [][]u8) -> %void { |
| 150 | 150 | private_function(); |
| 151 | 151 | stdout.printf("OK 2\n"); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | | fn private_function() => { |
| 154 | fn private_function() { |
| 155 | 155 | print_text(); |
| 156 | 156 | } |
| 157 | 157 | )SOURCE", "OK 1\nOK 2\n"); |
| ... | ... | @@ -161,11 +161,11 @@ import "std.zig"; |
| 161 | 161 | |
| 162 | 162 | // purposefully conflicting function with main.zig |
| 163 | 163 | // but it's private so it should be OK |
| 164 | | fn private_function() => { |
| 164 | fn private_function() { |
| 165 | 165 | stdout.printf("OK 1\n"); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | | pub fn print_text() => { |
| 168 | pub fn print_text() { |
| 169 | 169 | private_function(); |
| 170 | 170 | } |
| 171 | 171 | )SOURCE"); |
| ... | ... | @@ -176,7 +176,7 @@ pub fn print_text() => { |
| 176 | 176 | import "foo.zig"; |
| 177 | 177 | import "bar.zig"; |
| 178 | 178 | |
| 179 | | pub fn main(args: [][]u8) %void => { |
| 179 | pub fn main(args: [][]u8) -> %void { |
| 180 | 180 | foo_function(); |
| 181 | 181 | bar_function(); |
| 182 | 182 | } |
| ... | ... | @@ -184,7 +184,7 @@ pub fn main(args: [][]u8) %void => { |
| 184 | 184 | |
| 185 | 185 | add_source_file(tc, "foo.zig", R"SOURCE( |
| 186 | 186 | import "std.zig"; |
| 187 | | pub fn foo_function() => { |
| 187 | pub fn foo_function() { |
| 188 | 188 | stdout.printf("OK\n"); |
| 189 | 189 | } |
| 190 | 190 | )SOURCE"); |
| ... | ... | @@ -193,7 +193,7 @@ pub fn foo_function() => { |
| 193 | 193 | import "other.zig"; |
| 194 | 194 | import "std.zig"; |
| 195 | 195 | |
| 196 | | pub fn bar_function() => { |
| 196 | pub fn bar_function() { |
| 197 | 197 | if (foo_function()) { |
| 198 | 198 | stdout.printf("OK\n"); |
| 199 | 199 | } |
| ... | ... | @@ -201,7 +201,7 @@ pub fn bar_function() => { |
| 201 | 201 | )SOURCE"); |
| 202 | 202 | |
| 203 | 203 | add_source_file(tc, "other.zig", R"SOURCE( |
| 204 | | pub fn foo_function() bool => { |
| 204 | pub fn foo_function() -> bool { |
| 205 | 205 | // this one conflicts with the one from foo |
| 206 | 206 | return true; |
| 207 | 207 | } |
| ... | ... | @@ -211,7 +211,7 @@ pub fn foo_function() bool => { |
| 211 | 211 | add_simple_case("if statements", R"SOURCE( |
| 212 | 212 | import "std.zig"; |
| 213 | 213 | |
| 214 | | pub fn main(args: [][]u8) %void => { |
| 214 | pub fn main(args: [][]u8) -> %void { |
| 215 | 215 | if (1 != 0) { |
| 216 | 216 | stdout.printf("1 is true\n"); |
| 217 | 217 | } else { |
| ... | ... | @@ -231,11 +231,11 @@ pub fn main(args: [][]u8) %void => { |
| 231 | 231 | add_simple_case("params", R"SOURCE( |
| 232 | 232 | import "std.zig"; |
| 233 | 233 | |
| 234 | | fn add(a: i32, b: i32) i32 => { |
| 234 | fn add(a: i32, b: i32) -> i32 { |
| 235 | 235 | a + b |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | | pub fn main(args: [][]u8) %void => { |
| 238 | pub fn main(args: [][]u8) -> %void { |
| 239 | 239 | if (add(22, 11) == 33) { |
| 240 | 240 | stdout.printf("pass\n"); |
| 241 | 241 | } |
| ... | ... | @@ -245,7 +245,7 @@ pub fn main(args: [][]u8) %void => { |
| 245 | 245 | add_simple_case("goto", R"SOURCE( |
| 246 | 246 | import "std.zig"; |
| 247 | 247 | |
| 248 | | fn loop(a : i32) => { |
| 248 | fn loop(a : i32) { |
| 249 | 249 | if (a == 0) { |
| 250 | 250 | goto done; |
| 251 | 251 | } |
| ... | ... | @@ -256,7 +256,7 @@ done: |
| 256 | 256 | return; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | | pub fn main(args: [][]u8) %void => { |
| 259 | pub fn main(args: [][]u8) -> %void { |
| 260 | 260 | loop(3); |
| 261 | 261 | } |
| 262 | 262 | )SOURCE", "loop\nloop\nloop\n"); |
| ... | ... | @@ -264,7 +264,7 @@ pub fn main(args: [][]u8) %void => { |
| 264 | 264 | add_simple_case("local variables", R"SOURCE( |
| 265 | 265 | import "std.zig"; |
| 266 | 266 | |
| 267 | | pub fn main(args: [][]u8) %void => { |
| 267 | pub fn main(args: [][]u8) -> %void { |
| 268 | 268 | const a : i32 = 1; |
| 269 | 269 | const b = i32(2); |
| 270 | 270 | if (a + b == 3) { |
| ... | ... | @@ -276,7 +276,7 @@ pub fn main(args: [][]u8) %void => { |
| 276 | 276 | add_simple_case("bool literals", R"SOURCE( |
| 277 | 277 | import "std.zig"; |
| 278 | 278 | |
| 279 | | pub fn main(args: [][]u8) %void => { |
| 279 | pub fn main(args: [][]u8) -> %void { |
| 280 | 280 | if (true) { stdout.printf("OK 1\n"); } |
| 281 | 281 | if (false) { stdout.printf("BAD 1\n"); } |
| 282 | 282 | if (!true) { stdout.printf("BAD 2\n"); } |
| ... | ... | @@ -287,7 +287,7 @@ pub fn main(args: [][]u8) %void => { |
| 287 | 287 | add_simple_case("separate block scopes", R"SOURCE( |
| 288 | 288 | import "std.zig"; |
| 289 | 289 | |
| 290 | | pub fn main(args: [][]u8) %void => { |
| 290 | pub fn main(args: [][]u8) -> %void { |
| 291 | 291 | if (true) { |
| 292 | 292 | const no_conflict : i32 = 5; |
| 293 | 293 | if (no_conflict == 5) { stdout.printf("OK 1\n"); } |
| ... | ... | @@ -304,11 +304,11 @@ pub fn main(args: [][]u8) %void => { |
| 304 | 304 | add_simple_case("void parameters", R"SOURCE( |
| 305 | 305 | import "std.zig"; |
| 306 | 306 | |
| 307 | | pub fn main(args: [][]u8) %void => { |
| 307 | pub fn main(args: [][]u8) -> %void { |
| 308 | 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 | 312 | const v = b; |
| 313 | 313 | const vv : void = if (a == 1) {v} else {}; |
| 314 | 314 | if (a + c == 3) { stdout.printf("OK\n"); } |
| ... | ... | @@ -323,7 +323,7 @@ struct Foo { |
| 323 | 323 | b : i32, |
| 324 | 324 | c : void, |
| 325 | 325 | } |
| 326 | | pub fn main(args: [][]u8) %void => { |
| 326 | pub fn main(args: [][]u8) -> %void { |
| 327 | 327 | const foo = Foo { |
| 328 | 328 | .a = void{}, |
| 329 | 329 | .b = 1, |
| ... | ... | @@ -343,7 +343,7 @@ pub fn main(args: [][]u8) %void => { |
| 343 | 343 | add_simple_case("void arrays", R"SOURCE( |
| 344 | 344 | import "std.zig"; |
| 345 | 345 | |
| 346 | | pub fn main(args: [][]u8) %void => { |
| 346 | pub fn main(args: [][]u8) -> %void { |
| 347 | 347 | var array: [4]void; |
| 348 | 348 | array[0] = void{}; |
| 349 | 349 | array[1] = array[2]; |
| ... | ... | @@ -361,7 +361,7 @@ pub fn main(args: [][]u8) %void => { |
| 361 | 361 | add_simple_case("mutable local variables", R"SOURCE( |
| 362 | 362 | import "std.zig"; |
| 363 | 363 | |
| 364 | | pub fn main(args: [][]u8) %void => { |
| 364 | pub fn main(args: [][]u8) -> %void { |
| 365 | 365 | var zero : i32 = 0; |
| 366 | 366 | if (zero == 0) { stdout.printf("zero\n"); } |
| 367 | 367 | |
| ... | ... | @@ -376,7 +376,7 @@ pub fn main(args: [][]u8) %void => { |
| 376 | 376 | add_simple_case("arrays", R"SOURCE( |
| 377 | 377 | import "std.zig"; |
| 378 | 378 | |
| 379 | | pub fn main(args: [][]u8) %void => { |
| 379 | pub fn main(args: [][]u8) -> %void { |
| 380 | 380 | var array : [5]i32; |
| 381 | 381 | |
| 382 | 382 | var i : i32 = 0; |
| ... | ... | @@ -401,7 +401,7 @@ pub fn main(args: [][]u8) %void => { |
| 401 | 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 | 405 | a.len |
| 406 | 406 | } |
| 407 | 407 | )SOURCE", "OK\n"); |
| ... | ... | @@ -410,7 +410,7 @@ fn get_array_len(a: []i32) isize => { |
| 410 | 410 | add_simple_case("hello world without libc", R"SOURCE( |
| 411 | 411 | import "std.zig"; |
| 412 | 412 | |
| 413 | | pub fn main(args: [][]u8) %void => { |
| 413 | pub fn main(args: [][]u8) -> %void { |
| 414 | 414 | stdout.printf("Hello, world!\n"); |
| 415 | 415 | } |
| 416 | 416 | )SOURCE", "Hello, world!\n"); |
| ... | ... | @@ -419,7 +419,7 @@ pub fn main(args: [][]u8) %void => { |
| 419 | 419 | add_simple_case("a + b + c", R"SOURCE( |
| 420 | 420 | import "std.zig"; |
| 421 | 421 | |
| 422 | | pub fn main(args: [][]u8) %void => { |
| 422 | pub fn main(args: [][]u8) -> %void { |
| 423 | 423 | if (false || false || false) { stdout.printf("BAD 1\n"); } |
| 424 | 424 | if (true && true && false) { stdout.printf("BAD 2\n"); } |
| 425 | 425 | if (1 | 2 | 4 != 7) { stdout.printf("BAD 3\n"); } |
| ... | ... | @@ -440,7 +440,7 @@ pub fn main(args: [][]u8) %void => { |
| 440 | 440 | add_simple_case("short circuit", R"SOURCE( |
| 441 | 441 | import "std.zig"; |
| 442 | 442 | |
| 443 | | pub fn main(args: [][]u8) %void => { |
| 443 | pub fn main(args: [][]u8) -> %void { |
| 444 | 444 | if (true || { stdout.printf("BAD 1\n"); false }) { |
| 445 | 445 | stdout.printf("OK 1\n"); |
| 446 | 446 | } |
| ... | ... | @@ -461,7 +461,7 @@ pub fn main(args: [][]u8) %void => { |
| 461 | 461 | add_simple_case("modify operators", R"SOURCE( |
| 462 | 462 | import "std.zig"; |
| 463 | 463 | |
| 464 | | pub fn main(args: [][]u8) %void => { |
| 464 | pub fn main(args: [][]u8) -> %void { |
| 465 | 465 | var i : i32 = 0; |
| 466 | 466 | i += 5; if (i != 5) { stdout.printf("BAD +=\n"); } |
| 467 | 467 | i -= 2; if (i != 3) { stdout.printf("BAD -=\n"); } |
| ... | ... | @@ -483,10 +483,10 @@ pub fn main(args: [][]u8) %void => { |
| 483 | 483 | add_simple_case("number literals", R"SOURCE( |
| 484 | 484 | #link("c") |
| 485 | 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 | 490 | printf(c"\n"); |
| 491 | 491 | |
| 492 | 492 | printf(c"0: %llu\n", |
| ... | ... | @@ -612,7 +612,7 @@ export fn main(argc: i32, argv: &&u8) i32 => { |
| 612 | 612 | add_simple_case("structs", R"SOURCE( |
| 613 | 613 | import "std.zig"; |
| 614 | 614 | |
| 615 | | pub fn main(args: [][]u8) %void => { |
| 615 | pub fn main(args: [][]u8) -> %void { |
| 616 | 616 | var foo : Foo; |
| 617 | 617 | @memset(&foo, 0, @sizeof(Foo)); |
| 618 | 618 | foo.a += 1; |
| ... | ... | @@ -632,12 +632,12 @@ struct Foo { |
| 632 | 632 | b : bool, |
| 633 | 633 | c : f32, |
| 634 | 634 | } |
| 635 | | fn test_foo(foo : Foo) => { |
| 635 | fn test_foo(foo : Foo) { |
| 636 | 636 | if (!foo.b) { |
| 637 | 637 | stdout.printf("BAD\n"); |
| 638 | 638 | } |
| 639 | 639 | } |
| 640 | | fn test_mutation(foo : &Foo) => { |
| 640 | fn test_mutation(foo : &Foo) { |
| 641 | 641 | foo.c = 100; |
| 642 | 642 | } |
| 643 | 643 | struct Node { |
| ... | ... | @@ -648,7 +648,7 @@ struct Node { |
| 648 | 648 | struct Val { |
| 649 | 649 | x: i32, |
| 650 | 650 | } |
| 651 | | fn test_point_to_self() => { |
| 651 | fn test_point_to_self() { |
| 652 | 652 | var root : Node; |
| 653 | 653 | root.val.x = 1; |
| 654 | 654 | |
| ... | ... | @@ -662,7 +662,7 @@ fn test_point_to_self() => { |
| 662 | 662 | stdout.printf("BAD\n"); |
| 663 | 663 | } |
| 664 | 664 | } |
| 665 | | fn test_byval_assign() => { |
| 665 | fn test_byval_assign() { |
| 666 | 666 | var foo1 : Foo; |
| 667 | 667 | var foo2 : Foo; |
| 668 | 668 | |
| ... | ... | @@ -674,7 +674,7 @@ fn test_byval_assign() => { |
| 674 | 674 | |
| 675 | 675 | if (foo2.a != 1234) { stdout.printf("BAD - byval assignment failed\n"); } |
| 676 | 676 | } |
| 677 | | fn test_initializer() => { |
| 677 | fn test_initializer() { |
| 678 | 678 | const val = Val { .x = 42 }; |
| 679 | 679 | if (val.x != 42) { stdout.printf("BAD\n"); } |
| 680 | 680 | } |
| ... | ... | @@ -686,7 +686,7 @@ import "std.zig"; |
| 686 | 686 | const g1 : i32 = 1233 + 1; |
| 687 | 687 | var g2 : i32 = 0; |
| 688 | 688 | |
| 689 | | pub fn main(args: [][]u8) %void => { |
| 689 | pub fn main(args: [][]u8) -> %void { |
| 690 | 690 | if (g2 != 0) { stdout.printf("BAD\n"); } |
| 691 | 691 | g2 = g1; |
| 692 | 692 | if (g2 != 1234) { stdout.printf("BAD\n"); } |
| ... | ... | @@ -696,7 +696,7 @@ pub fn main(args: [][]u8) %void => { |
| 696 | 696 | |
| 697 | 697 | add_simple_case("while loop", R"SOURCE( |
| 698 | 698 | import "std.zig"; |
| 699 | | pub fn main(args: [][]u8) %void => { |
| 699 | pub fn main(args: [][]u8) -> %void { |
| 700 | 700 | var i : i32 = 0; |
| 701 | 701 | while (i < 4) { |
| 702 | 702 | stdout.printf("loop\n"); |
| ... | ... | @@ -704,10 +704,10 @@ pub fn main(args: [][]u8) %void => { |
| 704 | 704 | } |
| 705 | 705 | g(); |
| 706 | 706 | } |
| 707 | | fn g() i32 => { |
| 707 | fn g() -> i32 { |
| 708 | 708 | return f(); |
| 709 | 709 | } |
| 710 | | fn f() i32 => { |
| 710 | fn f() -> i32 { |
| 711 | 711 | while (true) { |
| 712 | 712 | return 0; |
| 713 | 713 | } |
| ... | ... | @@ -716,7 +716,7 @@ fn f() i32 => { |
| 716 | 716 | |
| 717 | 717 | add_simple_case("continue and break", R"SOURCE( |
| 718 | 718 | import "std.zig"; |
| 719 | | pub fn main(args: [][]u8) %void => { |
| 719 | pub fn main(args: [][]u8) -> %void { |
| 720 | 720 | var i : i32 = 0; |
| 721 | 721 | while (true) { |
| 722 | 722 | stdout.printf("loop\n"); |
| ... | ... | @@ -731,7 +731,7 @@ pub fn main(args: [][]u8) %void => { |
| 731 | 731 | |
| 732 | 732 | add_simple_case("maybe type", R"SOURCE( |
| 733 | 733 | import "std.zig"; |
| 734 | | pub fn main(args: [][]u8) %void => { |
| 734 | pub fn main(args: [][]u8) -> %void { |
| 735 | 735 | const x : ?bool = true; |
| 736 | 736 | |
| 737 | 737 | if (const y ?= x) { |
| ... | ... | @@ -764,14 +764,14 @@ pub fn main(args: [][]u8) %void => { |
| 764 | 764 | |
| 765 | 765 | add_simple_case("implicit cast after unreachable", R"SOURCE( |
| 766 | 766 | import "std.zig"; |
| 767 | | pub fn main(args: [][]u8) %void => { |
| 767 | pub fn main(args: [][]u8) -> %void { |
| 768 | 768 | const x = outer(); |
| 769 | 769 | if (x == 1234) { |
| 770 | 770 | stdout.printf("OK\n"); |
| 771 | 771 | } |
| 772 | 772 | } |
| 773 | | fn inner() i32 => { 1234 } |
| 774 | | fn outer() isize => { |
| 773 | fn inner() -> i32 { 1234 } |
| 774 | fn outer() -> isize { |
| 775 | 775 | return inner(); |
| 776 | 776 | } |
| 777 | 777 | )SOURCE", "OK\n"); |
| ... | ... | @@ -780,7 +780,7 @@ fn outer() isize => { |
| 780 | 780 | import "std.zig"; |
| 781 | 781 | const x: u16 = 13; |
| 782 | 782 | const z: @typeof(x) = 19; |
| 783 | | pub fn main(args: [][]u8) %void => { |
| 783 | pub fn main(args: [][]u8) -> %void { |
| 784 | 784 | const y: @typeof(x) = 120; |
| 785 | 785 | stdout.print_u64(@sizeof(@typeof(y))); |
| 786 | 786 | stdout.printf("\n"); |
| ... | ... | @@ -791,11 +791,11 @@ pub fn main(args: [][]u8) %void => { |
| 791 | 791 | import "std.zig"; |
| 792 | 792 | struct Rand { |
| 793 | 793 | seed: u32, |
| 794 | | pub fn get_seed(r: Rand) u32 => { |
| 794 | pub fn get_seed(r: Rand) -> u32 { |
| 795 | 795 | r.seed |
| 796 | 796 | } |
| 797 | 797 | } |
| 798 | | pub fn main(args: [][]u8) %void => { |
| 798 | pub fn main(args: [][]u8) -> %void { |
| 799 | 799 | const r = Rand {.seed = 1234}; |
| 800 | 800 | if (r.get_seed() != 1234) { |
| 801 | 801 | stdout.printf("BAD seed\n"); |
| ... | ... | @@ -807,7 +807,7 @@ pub fn main(args: [][]u8) %void => { |
| 807 | 807 | add_simple_case("pointer dereferencing", R"SOURCE( |
| 808 | 808 | import "std.zig"; |
| 809 | 809 | |
| 810 | | pub fn main(args: [][]u8) %void => { |
| 810 | pub fn main(args: [][]u8) -> %void { |
| 811 | 811 | var x = i32(3); |
| 812 | 812 | const y = &x; |
| 813 | 813 | |
| ... | ... | @@ -828,7 +828,7 @@ import "std.zig"; |
| 828 | 828 | |
| 829 | 829 | const ARRAY_SIZE : i8 = 20; |
| 830 | 830 | |
| 831 | | pub fn main(args: [][]u8) %void => { |
| 831 | pub fn main(args: [][]u8) -> %void { |
| 832 | 832 | var array : [ARRAY_SIZE]u8; |
| 833 | 833 | stdout.print_u64(@sizeof(@typeof(array))); |
| 834 | 834 | stdout.printf("\n"); |
| ... | ... | @@ -837,7 +837,7 @@ pub fn main(args: [][]u8) %void => { |
| 837 | 837 | |
| 838 | 838 | add_simple_case("@min_value() and @max_value()", R"SOURCE( |
| 839 | 839 | import "std.zig"; |
| 840 | | pub fn main(args: [][]u8) %void => { |
| 840 | pub fn main(args: [][]u8) -> %void { |
| 841 | 841 | stdout.printf("max u8: "); |
| 842 | 842 | stdout.print_u64(@max_value(u8)); |
| 843 | 843 | stdout.printf("\n"); |
| ... | ... | @@ -923,7 +923,7 @@ pub fn main(args: [][]u8) %void => { |
| 923 | 923 | |
| 924 | 924 | add_simple_case("slicing", R"SOURCE( |
| 925 | 925 | import "std.zig"; |
| 926 | | pub fn main(args: [][]u8) %void => { |
| 926 | pub fn main(args: [][]u8) -> %void { |
| 927 | 927 | var array : [20]i32; |
| 928 | 928 | |
| 929 | 929 | array[5] = 1234; |
| ... | ... | @@ -950,12 +950,12 @@ pub fn main(args: [][]u8) %void => { |
| 950 | 950 | |
| 951 | 951 | add_simple_case("else if expression", R"SOURCE( |
| 952 | 952 | import "std.zig"; |
| 953 | | pub fn main(args: [][]u8) %void => { |
| 953 | pub fn main(args: [][]u8) -> %void { |
| 954 | 954 | if (f(1) == 1) { |
| 955 | 955 | stdout.printf("OK\n"); |
| 956 | 956 | } |
| 957 | 957 | } |
| 958 | | fn f(c: u8) u8 => { |
| 958 | fn f(c: u8) -> u8 { |
| 959 | 959 | if (c == 0) { |
| 960 | 960 | 0 |
| 961 | 961 | } else if (c == 1) { |
| ... | ... | @@ -968,7 +968,7 @@ fn f(c: u8) u8 => { |
| 968 | 968 | |
| 969 | 969 | add_simple_case("overflow intrinsics", R"SOURCE( |
| 970 | 970 | import "std.zig"; |
| 971 | | pub fn main(args: [][]u8) %void => { |
| 971 | pub fn main(args: [][]u8) -> %void { |
| 972 | 972 | var result: u8; |
| 973 | 973 | if (!@add_with_overflow(u8, 250, 100, &result)) { |
| 974 | 974 | stdout.printf("BAD\n"); |
| ... | ... | @@ -985,7 +985,7 @@ pub fn main(args: [][]u8) %void => { |
| 985 | 985 | |
| 986 | 986 | add_simple_case("memcpy and memset intrinsics", R"SOURCE( |
| 987 | 987 | import "std.zig"; |
| 988 | | pub fn main(args: [][]u8) %void => { |
| 988 | pub fn main(args: [][]u8) -> %void { |
| 989 | 989 | var foo : [20]u8; |
| 990 | 990 | var bar : [20]u8; |
| 991 | 991 | |
| ... | ... | @@ -1005,10 +1005,10 @@ import "std.zig"; |
| 1005 | 1005 | const z : @typeof(stdin_fileno) = 0; |
| 1006 | 1006 | const x : @typeof(y) = 1234; |
| 1007 | 1007 | const y : u16 = 5678; |
| 1008 | | pub fn main(args: [][]u8) %void => { |
| 1008 | pub fn main(args: [][]u8) -> %void { |
| 1009 | 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 | 1012 | stdout.printf("OK\n"); |
| 1013 | 1013 | return 0; |
| 1014 | 1014 | } |
| ... | ... | @@ -1036,7 +1036,7 @@ enum Bar { |
| 1036 | 1036 | D, |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | | pub fn main(args: [][]u8) %void => { |
| 1039 | pub fn main(args: [][]u8) -> %void { |
| 1040 | 1040 | const foo1 = Foo.One(13); |
| 1041 | 1041 | const foo2 = Foo.Two(Point { .x = 1234, .y = 5678, }); |
| 1042 | 1042 | const bar = Bar.B; |
| ... | ... | @@ -1067,7 +1067,7 @@ pub fn main(args: [][]u8) %void => { |
| 1067 | 1067 | add_simple_case("array literal", R"SOURCE( |
| 1068 | 1068 | import "std.zig"; |
| 1069 | 1069 | |
| 1070 | | pub fn main(args: [][]u8) %void => { |
| 1070 | pub fn main(args: [][]u8) -> %void { |
| 1071 | 1071 | const HEX_MULT = []u16{4096, 256, 16, 1}; |
| 1072 | 1072 | |
| 1073 | 1073 | if (HEX_MULT.len != 4) { |
| ... | ... | @@ -1085,7 +1085,7 @@ pub fn main(args: [][]u8) %void => { |
| 1085 | 1085 | add_simple_case("nested arrays", R"SOURCE( |
| 1086 | 1086 | import "std.zig"; |
| 1087 | 1087 | |
| 1088 | | pub fn main(args: [][]u8) %void => { |
| 1088 | pub fn main(args: [][]u8) -> %void { |
| 1089 | 1089 | const array_of_strings = [][]u8 {"hello", "this", "is", "my", "thing"}; |
| 1090 | 1090 | var i: @typeof(array_of_strings.len) = 0; |
| 1091 | 1091 | while (i < array_of_strings.len) { |
| ... | ... | @@ -1099,7 +1099,7 @@ pub fn main(args: [][]u8) %void => { |
| 1099 | 1099 | add_simple_case("for loops", R"SOURCE( |
| 1100 | 1100 | import "std.zig"; |
| 1101 | 1101 | |
| 1102 | | pub fn main(args: [][]u8) %void => { |
| 1102 | pub fn main(args: [][]u8) -> %void { |
| 1103 | 1103 | const array = []u8 {9, 8, 7, 6}; |
| 1104 | 1104 | for (item, array) { |
| 1105 | 1105 | stdout.print_u64(item); |
| ... | ... | @@ -1124,7 +1124,7 @@ pub fn main(args: [][]u8) %void => { |
| 1124 | 1124 | add_simple_case("function pointers", R"SOURCE( |
| 1125 | 1125 | import "std.zig"; |
| 1126 | 1126 | |
| 1127 | | pub fn main(args: [][]u8) %void => { |
| 1127 | pub fn main(args: [][]u8) -> %void { |
| 1128 | 1128 | const fns = []@typeof(fn1) { fn1, fn2, fn3, fn4, }; |
| 1129 | 1129 | for (f, fns) { |
| 1130 | 1130 | stdout.print_u64(f()); |
| ... | ... | @@ -1132,10 +1132,10 @@ pub fn main(args: [][]u8) %void => { |
| 1132 | 1132 | } |
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | | fn fn1() u32 => {5} |
| 1136 | | fn fn2() u32 => {6} |
| 1137 | | fn fn3() u32 => {7} |
| 1138 | | fn fn4() u32 => {8} |
| 1135 | fn fn1() -> u32 {5} |
| 1136 | fn fn2() -> u32 {6} |
| 1137 | fn fn3() -> u32 {7} |
| 1138 | fn fn4() -> u32 {8} |
| 1139 | 1139 | )SOURCE", "5\n6\n7\n8\n"); |
| 1140 | 1140 | |
| 1141 | 1141 | add_simple_case("switch statement", R"SOURCE( |
| ... | ... | @@ -1148,7 +1148,7 @@ enum Foo { |
| 1148 | 1148 | D, |
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | | pub fn main(args: [][]u8) %void => { |
| 1151 | pub fn main(args: [][]u8) -> %void { |
| 1152 | 1152 | const foo = Foo.C; |
| 1153 | 1153 | const val: i32 = switch (foo) { |
| 1154 | 1154 | Foo.A => 1, |
| ... | ... | @@ -1169,7 +1169,7 @@ import "std.zig"; |
| 1169 | 1169 | |
| 1170 | 1170 | const ten = 10; |
| 1171 | 1171 | |
| 1172 | | pub fn main(args: [][]u8) %void => { |
| 1172 | pub fn main(args: [][]u8) -> %void { |
| 1173 | 1173 | const one = 1; |
| 1174 | 1174 | const eleven = ten + one; |
| 1175 | 1175 | |
| ... | ... | @@ -1188,7 +1188,7 @@ struct Foo { |
| 1188 | 1188 | y: bool, |
| 1189 | 1189 | } |
| 1190 | 1190 | var foo = Foo { .x = 13, .y = true, }; |
| 1191 | | pub fn main(args: [][]u8) %void => { |
| 1191 | pub fn main(args: [][]u8) -> %void { |
| 1192 | 1192 | foo.x += 1; |
| 1193 | 1193 | if (foo.x != 14) { |
| 1194 | 1194 | stdout.printf("BAD\n"); |
| ... | ... | @@ -1201,7 +1201,7 @@ pub fn main(args: [][]u8) %void => { |
| 1201 | 1201 | add_simple_case("statically initialized array literal", R"SOURCE( |
| 1202 | 1202 | import "std.zig"; |
| 1203 | 1203 | const x = []u8{1,2,3,4}; |
| 1204 | | pub fn main(args: [][]u8) %void => { |
| 1204 | pub fn main(args: [][]u8) -> %void { |
| 1205 | 1205 | const y : [4]u8 = x; |
| 1206 | 1206 | if (y[3] != 4) { |
| 1207 | 1207 | stdout.printf("BAD\n"); |
| ... | ... | @@ -1215,7 +1215,7 @@ pub fn main(args: [][]u8) %void => { |
| 1215 | 1215 | import "std.zig"; |
| 1216 | 1216 | error err1; |
| 1217 | 1217 | error err2; |
| 1218 | | pub fn main(args: [][]u8) %void => { |
| 1218 | pub fn main(args: [][]u8) -> %void { |
| 1219 | 1219 | const a = i32(error.err1); |
| 1220 | 1220 | const b = i32(error.err2); |
| 1221 | 1221 | if (a == b) { |
| ... | ... | @@ -1228,7 +1228,7 @@ pub fn main(args: [][]u8) %void => { |
| 1228 | 1228 | |
| 1229 | 1229 | add_simple_case("return with implicit cast from while loop", R"SOURCE( |
| 1230 | 1230 | import "std.zig"; |
| 1231 | | pub fn main(args: [][]u8) %void => { |
| 1231 | pub fn main(args: [][]u8) -> %void { |
| 1232 | 1232 | while (true) { |
| 1233 | 1233 | stdout.printf("OK\n"); |
| 1234 | 1234 | return; |
| ... | ... | @@ -1242,13 +1242,13 @@ struct Foo { |
| 1242 | 1242 | x: i32, |
| 1243 | 1243 | y: i32, |
| 1244 | 1244 | } |
| 1245 | | fn make_foo(x: i32, y: i32) Foo => { |
| 1245 | fn make_foo(x: i32, y: i32) -> Foo { |
| 1246 | 1246 | Foo { |
| 1247 | 1247 | .x = x, |
| 1248 | 1248 | .y = y, |
| 1249 | 1249 | } |
| 1250 | 1250 | } |
| 1251 | | pub fn main(args: [][]u8) %void => { |
| 1251 | pub fn main(args: [][]u8) -> %void { |
| 1252 | 1252 | const foo = make_foo(1234, 5678); |
| 1253 | 1253 | if (foo.y != 5678) { |
| 1254 | 1254 | stdout.printf("BAD\n"); |
| ... | ... | @@ -1260,14 +1260,14 @@ pub fn main(args: [][]u8) %void => { |
| 1260 | 1260 | add_simple_case("%% binary operator", R"SOURCE( |
| 1261 | 1261 | import "std.zig"; |
| 1262 | 1262 | error ItBroke; |
| 1263 | | fn g(x: bool) %isize => { |
| 1263 | fn g(x: bool) -> %isize { |
| 1264 | 1264 | if (x) { |
| 1265 | 1265 | error.ItBroke |
| 1266 | 1266 | } else { |
| 1267 | 1267 | 10 |
| 1268 | 1268 | } |
| 1269 | 1269 | } |
| 1270 | | pub fn main(args: [][]u8) %void => { |
| 1270 | pub fn main(args: [][]u8) -> %void { |
| 1271 | 1271 | const a = g(true) %% 3; |
| 1272 | 1272 | const b = g(false) %% 3; |
| 1273 | 1273 | if (a != 3) { |
| ... | ... | @@ -1286,8 +1286,8 @@ pub fn main(args: [][]u8) %void => { |
| 1286 | 1286 | |
| 1287 | 1287 | static void add_compile_failure_test_cases(void) { |
| 1288 | 1288 | add_compile_fail_case("multiple function definitions", R"SOURCE( |
| 1289 | | fn a() => {} |
| 1290 | | fn a() => {} |
| 1289 | fn a() {} |
| 1290 | fn a() {} |
| 1291 | 1291 | )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'a'"); |
| 1292 | 1292 | |
| 1293 | 1293 | add_compile_fail_case("bad directive", R"SOURCE( |
| ... | ... | @@ -1296,46 +1296,46 @@ extern { |
| 1296 | 1296 | fn b(); |
| 1297 | 1297 | } |
| 1298 | 1298 | #bogus2("") |
| 1299 | | fn a() => {} |
| 1299 | fn a() {} |
| 1300 | 1300 | )SOURCE", 2, ".tmp_source.zig:2:1: error: invalid directive: 'bogus1'", |
| 1301 | 1301 | ".tmp_source.zig:6:1: error: invalid directive: 'bogus2'"); |
| 1302 | 1302 | |
| 1303 | 1303 | add_compile_fail_case("unreachable with return", R"SOURCE( |
| 1304 | | fn a() unreachable => {return;} |
| 1304 | fn a() -> unreachable {return;} |
| 1305 | 1305 | )SOURCE", 1, ".tmp_source.zig:2:24: error: expected type 'unreachable', got 'void'"); |
| 1306 | 1306 | |
| 1307 | 1307 | add_compile_fail_case("control reaches end of non-void function", R"SOURCE( |
| 1308 | | fn a() i32 => {} |
| 1308 | fn a() -> i32 {} |
| 1309 | 1309 | )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', got 'void'"); |
| 1310 | 1310 | |
| 1311 | 1311 | add_compile_fail_case("undefined function call", R"SOURCE( |
| 1312 | | fn a() => { |
| 1312 | fn a() { |
| 1313 | 1313 | b(); |
| 1314 | 1314 | } |
| 1315 | 1315 | )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'"); |
| 1316 | 1316 | |
| 1317 | 1317 | add_compile_fail_case("wrong number of arguments", R"SOURCE( |
| 1318 | | fn a() => { |
| 1318 | fn a() { |
| 1319 | 1319 | b(1); |
| 1320 | 1320 | } |
| 1321 | | fn b(a: i32, b: i32, c: i32) => { } |
| 1321 | fn b(a: i32, b: i32, c: i32) { } |
| 1322 | 1322 | )SOURCE", 1, ".tmp_source.zig:3:6: error: expected 3 arguments, got 1"); |
| 1323 | 1323 | |
| 1324 | 1324 | add_compile_fail_case("invalid type", R"SOURCE( |
| 1325 | | fn a() bogus => {} |
| 1326 | | )SOURCE", 1, ".tmp_source.zig:2:8: error: use of undeclared identifier 'bogus'"); |
| 1325 | fn a() -> bogus {} |
| 1326 | )SOURCE", 1, ".tmp_source.zig:2:11: error: use of undeclared identifier 'bogus'"); |
| 1327 | 1327 | |
| 1328 | 1328 | add_compile_fail_case("pointer to unreachable", R"SOURCE( |
| 1329 | | fn a() &unreachable => {} |
| 1330 | | )SOURCE", 1, ".tmp_source.zig:2:8: error: pointer to unreachable not allowed"); |
| 1329 | fn a() -> &unreachable {} |
| 1330 | )SOURCE", 1, ".tmp_source.zig:2:11: error: pointer to unreachable not allowed"); |
| 1331 | 1331 | |
| 1332 | 1332 | add_compile_fail_case("unreachable code", R"SOURCE( |
| 1333 | | fn a() => { |
| 1333 | fn a() { |
| 1334 | 1334 | return; |
| 1335 | 1335 | b(); |
| 1336 | 1336 | } |
| 1337 | 1337 | |
| 1338 | | fn b() => {} |
| 1338 | fn b() {} |
| 1339 | 1339 | )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code"); |
| 1340 | 1340 | |
| 1341 | 1341 | add_compile_fail_case("bad version string", R"SOURCE( |
| ... | ... | @@ -1348,7 +1348,7 @@ import "bogus-does-not-exist.zig"; |
| 1348 | 1348 | )SOURCE", 1, ".tmp_source.zig:2:1: error: unable to find 'bogus-does-not-exist.zig'"); |
| 1349 | 1349 | |
| 1350 | 1350 | add_compile_fail_case("undeclared identifier", R"SOURCE( |
| 1351 | | fn a() => { |
| 1351 | fn a() { |
| 1352 | 1352 | b + |
| 1353 | 1353 | c |
| 1354 | 1354 | } |
| ... | ... | @@ -1357,95 +1357,95 @@ fn a() => { |
| 1357 | 1357 | ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'"); |
| 1358 | 1358 | |
| 1359 | 1359 | add_compile_fail_case("goto cause unreachable code", R"SOURCE( |
| 1360 | | fn a() => { |
| 1360 | fn a() { |
| 1361 | 1361 | goto done; |
| 1362 | 1362 | b(); |
| 1363 | 1363 | done: |
| 1364 | 1364 | return; |
| 1365 | 1365 | } |
| 1366 | | fn b() => {} |
| 1366 | fn b() {} |
| 1367 | 1367 | )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code"); |
| 1368 | 1368 | |
| 1369 | 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 | 1372 | )SOURCE", 1, ".tmp_source.zig:2:15: error: redeclaration of variable 'a'"); |
| 1373 | 1373 | |
| 1374 | 1374 | add_compile_fail_case("local variable redeclaration", R"SOURCE( |
| 1375 | | fn f() => { |
| 1375 | fn f() { |
| 1376 | 1376 | const a : i32 = 0; |
| 1377 | 1377 | const a = 0; |
| 1378 | 1378 | } |
| 1379 | 1379 | )SOURCE", 1, ".tmp_source.zig:4:5: error: redeclaration of variable 'a'"); |
| 1380 | 1380 | |
| 1381 | 1381 | add_compile_fail_case("local variable redeclares parameter", R"SOURCE( |
| 1382 | | fn f(a : i32) => { |
| 1382 | fn f(a : i32) { |
| 1383 | 1383 | const a = 0; |
| 1384 | 1384 | } |
| 1385 | 1385 | )SOURCE", 1, ".tmp_source.zig:3:5: error: redeclaration of variable 'a'"); |
| 1386 | 1386 | |
| 1387 | 1387 | add_compile_fail_case("variable has wrong type", R"SOURCE( |
| 1388 | | fn f() i32 => { |
| 1388 | fn f() -> i32 { |
| 1389 | 1389 | const a = c"a"; |
| 1390 | 1390 | a |
| 1391 | 1391 | } |
| 1392 | 1392 | )SOURCE", 1, ".tmp_source.zig:4:5: error: expected type 'i32', got '&const u8'"); |
| 1393 | 1393 | |
| 1394 | 1394 | add_compile_fail_case("if condition is bool, not int", R"SOURCE( |
| 1395 | | fn f() => { |
| 1395 | fn f() { |
| 1396 | 1396 | if (0) {} |
| 1397 | 1397 | } |
| 1398 | 1398 | )SOURCE", 1, ".tmp_source.zig:3:9: error: value 0 cannot be represented in type 'bool'"); |
| 1399 | 1399 | |
| 1400 | 1400 | add_compile_fail_case("assign unreachable", R"SOURCE( |
| 1401 | | fn f() => { |
| 1401 | fn f() { |
| 1402 | 1402 | const a = return; |
| 1403 | 1403 | } |
| 1404 | 1404 | )SOURCE", 1, ".tmp_source.zig:3:5: error: variable initialization is unreachable"); |
| 1405 | 1405 | |
| 1406 | 1406 | add_compile_fail_case("unreachable variable", R"SOURCE( |
| 1407 | | fn f() => { |
| 1407 | fn f() { |
| 1408 | 1408 | const a : unreachable = return; |
| 1409 | 1409 | } |
| 1410 | 1410 | )SOURCE", 1, ".tmp_source.zig:3:15: error: variable of type 'unreachable' not allowed"); |
| 1411 | 1411 | |
| 1412 | 1412 | add_compile_fail_case("unreachable parameter", R"SOURCE( |
| 1413 | | fn f(a : unreachable) => {} |
| 1413 | fn f(a : unreachable) {} |
| 1414 | 1414 | )SOURCE", 1, ".tmp_source.zig:2:10: error: parameter of type 'unreachable' not allowed"); |
| 1415 | 1415 | |
| 1416 | 1416 | add_compile_fail_case("unused label", R"SOURCE( |
| 1417 | | fn f() => { |
| 1417 | fn f() { |
| 1418 | 1418 | a_label: |
| 1419 | 1419 | } |
| 1420 | 1420 | )SOURCE", 1, ".tmp_source.zig:3:1: error: label 'a_label' defined but not used"); |
| 1421 | 1421 | |
| 1422 | 1422 | add_compile_fail_case("bad assignment target", R"SOURCE( |
| 1423 | | fn f() => { |
| 1423 | fn f() { |
| 1424 | 1424 | 3 = 3; |
| 1425 | 1425 | } |
| 1426 | 1426 | )SOURCE", 1, ".tmp_source.zig:3:5: error: invalid assignment target"); |
| 1427 | 1427 | |
| 1428 | 1428 | add_compile_fail_case("assign to constant variable", R"SOURCE( |
| 1429 | | fn f() => { |
| 1429 | fn f() { |
| 1430 | 1430 | const a = 3; |
| 1431 | 1431 | a = 4; |
| 1432 | 1432 | } |
| 1433 | 1433 | )SOURCE", 1, ".tmp_source.zig:4:5: error: cannot assign to constant"); |
| 1434 | 1434 | |
| 1435 | 1435 | add_compile_fail_case("use of undeclared identifier", R"SOURCE( |
| 1436 | | fn f() => { |
| 1436 | fn f() { |
| 1437 | 1437 | b = 3; |
| 1438 | 1438 | } |
| 1439 | 1439 | )SOURCE", 1, ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'"); |
| 1440 | 1440 | |
| 1441 | 1441 | add_compile_fail_case("const is a statement, not an expression", R"SOURCE( |
| 1442 | | fn f() => { |
| 1442 | fn f() { |
| 1443 | 1443 | (const a = 0); |
| 1444 | 1444 | } |
| 1445 | 1445 | )SOURCE", 1, ".tmp_source.zig:3:6: error: invalid token: 'const'"); |
| 1446 | 1446 | |
| 1447 | 1447 | add_compile_fail_case("array access errors", R"SOURCE( |
| 1448 | | fn f() => { |
| 1448 | fn f() { |
| 1449 | 1449 | var bad : bool; |
| 1450 | 1450 | i[i] = i[i]; |
| 1451 | 1451 | bad[bad] = bad[bad]; |
| ... | ... | @@ -1460,19 +1460,19 @@ fn f() => { |
| 1460 | 1460 | ".tmp_source.zig:5:20: error: expected type 'isize', got 'bool'"); |
| 1461 | 1461 | |
| 1462 | 1462 | add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE( |
| 1463 | | fn f(...) => {} |
| 1463 | fn f(...) {} |
| 1464 | 1464 | )SOURCE", 1, ".tmp_source.zig:2:1: error: variadic arguments only allowed in extern functions"); |
| 1465 | 1465 | |
| 1466 | 1466 | add_compile_fail_case("write to const global variable", R"SOURCE( |
| 1467 | 1467 | const x : i32 = 99; |
| 1468 | | fn f() => { |
| 1468 | fn f() { |
| 1469 | 1469 | x = 1; |
| 1470 | 1470 | } |
| 1471 | 1471 | )SOURCE", 1, ".tmp_source.zig:4:5: error: cannot assign to constant"); |
| 1472 | 1472 | |
| 1473 | 1473 | |
| 1474 | 1474 | add_compile_fail_case("missing else clause", R"SOURCE( |
| 1475 | | fn f() => { |
| 1475 | fn f() { |
| 1476 | 1476 | const x : i32 = if (true) { 1 }; |
| 1477 | 1477 | const y = if (true) { i32(1) }; |
| 1478 | 1478 | } |
| ... | ... | @@ -1491,7 +1491,7 @@ struct C { a : A, } |
| 1491 | 1491 | |
| 1492 | 1492 | add_compile_fail_case("invalid struct field", R"SOURCE( |
| 1493 | 1493 | struct A { x : i32, } |
| 1494 | | fn f() => { |
| 1494 | fn f() { |
| 1495 | 1495 | var a : A; |
| 1496 | 1496 | a.foo = 1; |
| 1497 | 1497 | const y = a.bar; |
| ... | ... | @@ -1522,7 +1522,7 @@ var a : i32 = 2; |
| 1522 | 1522 | |
| 1523 | 1523 | add_compile_fail_case("byvalue struct on exported functions", R"SOURCE( |
| 1524 | 1524 | struct A { x : i32, } |
| 1525 | | export fn f(a : A) => {} |
| 1525 | export fn f(a : A) {} |
| 1526 | 1526 | )SOURCE", 1, ".tmp_source.zig:3:13: error: byvalue struct parameters not yet supported on exported functions"); |
| 1527 | 1527 | |
| 1528 | 1528 | add_compile_fail_case("duplicate field in struct value expression", R"SOURCE( |
| ... | ... | @@ -1531,7 +1531,7 @@ struct A { |
| 1531 | 1531 | y : i32, |
| 1532 | 1532 | z : i32, |
| 1533 | 1533 | } |
| 1534 | | fn f() => { |
| 1534 | fn f() { |
| 1535 | 1535 | const a = A { |
| 1536 | 1536 | .z = 1, |
| 1537 | 1537 | .y = 2, |
| ... | ... | @@ -1547,7 +1547,7 @@ struct A { |
| 1547 | 1547 | y : i32, |
| 1548 | 1548 | z : i32, |
| 1549 | 1549 | } |
| 1550 | | fn f() => { |
| 1550 | fn f() { |
| 1551 | 1551 | // we want the error on the '{' not the 'A' because |
| 1552 | 1552 | // the A could be a complicated expression |
| 1553 | 1553 | const a = A { |
| ... | ... | @@ -1563,7 +1563,7 @@ struct A { |
| 1563 | 1563 | y : i32, |
| 1564 | 1564 | z : i32, |
| 1565 | 1565 | } |
| 1566 | | fn f() => { |
| 1566 | fn f() { |
| 1567 | 1567 | const a = A { |
| 1568 | 1568 | .z = 4, |
| 1569 | 1569 | .y = 2, |
| ... | ... | @@ -1573,33 +1573,33 @@ fn f() => { |
| 1573 | 1573 | )SOURCE", 1, ".tmp_source.zig:11:9: error: no member named 'foo' in 'A'"); |
| 1574 | 1574 | |
| 1575 | 1575 | add_compile_fail_case("invalid break expression", R"SOURCE( |
| 1576 | | fn f() => { |
| 1576 | fn f() { |
| 1577 | 1577 | break; |
| 1578 | 1578 | } |
| 1579 | 1579 | )SOURCE", 1, ".tmp_source.zig:3:5: error: 'break' expression outside loop"); |
| 1580 | 1580 | |
| 1581 | 1581 | add_compile_fail_case("invalid continue expression", R"SOURCE( |
| 1582 | | fn f() => { |
| 1582 | fn f() { |
| 1583 | 1583 | continue; |
| 1584 | 1584 | } |
| 1585 | 1585 | )SOURCE", 1, ".tmp_source.zig:3:5: error: 'continue' expression outside loop"); |
| 1586 | 1586 | |
| 1587 | 1587 | add_compile_fail_case("invalid maybe type", R"SOURCE( |
| 1588 | | fn f() => { |
| 1588 | fn f() { |
| 1589 | 1589 | if (const x ?= true) { } |
| 1590 | 1590 | } |
| 1591 | 1591 | )SOURCE", 1, ".tmp_source.zig:3:20: error: expected maybe type"); |
| 1592 | 1592 | |
| 1593 | 1593 | add_compile_fail_case("cast unreachable", R"SOURCE( |
| 1594 | | fn f() i32 => { |
| 1594 | fn f() -> i32 { |
| 1595 | 1595 | i32(return 1) |
| 1596 | 1596 | } |
| 1597 | 1597 | )SOURCE", 1, ".tmp_source.zig:3:8: error: invalid cast from type 'unreachable' to 'i32'"); |
| 1598 | 1598 | |
| 1599 | 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 | 1604 | add_compile_fail_case("top level decl dependency loop", R"SOURCE( |
| 1605 | 1605 | const a : @typeof(b) = 0; |
| ... | ... | @@ -1607,7 +1607,7 @@ const b : @typeof(a) = 0; |
| 1607 | 1607 | )SOURCE", 1, ".tmp_source.zig:3:19: error: use of undeclared identifier 'a'"); |
| 1608 | 1608 | |
| 1609 | 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 | 1611 | )SOURCE", 1, ".tmp_source.zig:2:6: error: noalias on non-pointer parameter"); |
| 1612 | 1612 | |
| 1613 | 1613 | add_compile_fail_case("struct init syntax for array", R"SOURCE( |
| ... | ... | @@ -1622,14 +1622,14 @@ var foo = u8; |
| 1622 | 1622 | struct Foo {} |
| 1623 | 1623 | struct Bar {} |
| 1624 | 1624 | |
| 1625 | | fn f(Foo: i32) => { |
| 1625 | fn f(Foo: i32) { |
| 1626 | 1626 | var Bar : i32; |
| 1627 | 1627 | } |
| 1628 | 1628 | )SOURCE", 2, ".tmp_source.zig:5:6: error: variable shadows type 'Foo'", |
| 1629 | 1629 | ".tmp_source.zig:6:5: error: variable shadows type 'Bar'"); |
| 1630 | 1630 | |
| 1631 | 1631 | add_compile_fail_case("multiple else prongs in a switch", R"SOURCE( |
| 1632 | | fn f() => { |
| 1632 | fn f() { |
| 1633 | 1633 | const value: bool = switch (u32(111)) { |
| 1634 | 1634 | 1234 => false, |
| 1635 | 1635 | else => true, |
| ... | ... | @@ -1640,7 +1640,7 @@ fn f() => { |
| 1640 | 1640 | |
| 1641 | 1641 | add_compile_fail_case("global variable initializer must be constant expression", R"SOURCE( |
| 1642 | 1642 | extern { |
| 1643 | | fn foo() i32; |
| 1643 | fn foo() -> i32; |
| 1644 | 1644 | } |
| 1645 | 1645 | const x = foo(); |
| 1646 | 1646 | )SOURCE", 1, ".tmp_source.zig:5:11: error: global variable initializer requires constant expression"); |