| ... | ... | @@ -535,4 +535,68 @@ pub fn addCases(ctx: *TestContext) !void { |
| 535 | 535 | \\} |
| 536 | 536 | , "2\n"); |
| 537 | 537 | } |
| 538 | |
| 539 | { |
| 540 | var case = ctx.exe("wasm error unions", wasi); |
| 541 | |
| 542 | case.addCompareOutput( |
| 543 | \\pub export fn _start() void { |
| 544 | \\ var e1 = error.Foo; |
| 545 | \\ var e2 = error.Bar; |
| 546 | \\ assert(e1 != e2); |
| 547 | \\ assert(e1 == error.Foo); |
| 548 | \\ assert(e2 == error.Bar); |
| 549 | \\} |
| 550 | \\ |
| 551 | \\fn assert(b: bool) void { |
| 552 | \\ if (!b) unreachable; |
| 553 | \\} |
| 554 | , ""); |
| 555 | |
| 556 | case.addCompareOutput( |
| 557 | \\pub export fn _start() u32 { |
| 558 | \\ var e: anyerror!u32 = 5; |
| 559 | \\ const i = e catch 10; |
| 560 | \\ return i; |
| 561 | \\} |
| 562 | , "5\n"); |
| 563 | |
| 564 | case.addCompareOutput( |
| 565 | \\pub export fn _start() u32 { |
| 566 | \\ var e: anyerror!u32 = error.Foo; |
| 567 | \\ const i = e catch 10; |
| 568 | \\ return i; |
| 569 | \\} |
| 570 | , "10\n"); |
| 571 | |
| 572 | case.addCompareOutput( |
| 573 | \\pub export fn _start() u32 { |
| 574 | \\ var e = foo(); |
| 575 | \\ const i = e catch 69; |
| 576 | \\ return i; |
| 577 | \\} |
| 578 | \\ |
| 579 | \\fn foo() anyerror!u32 { |
| 580 | \\ return 5; |
| 581 | \\} |
| 582 | , "5\n"); |
| 583 | } |
| 584 | |
| 585 | { |
| 586 | // TODO implement Type equality comparison of error unions in SEMA |
| 587 | // before we can incrementally compile functions with an error union as return type |
| 588 | var case = ctx.exe("wasm error union part 2", wasi); |
| 589 | |
| 590 | case.addCompareOutput( |
| 591 | \\pub export fn _start() u32 { |
| 592 | \\ var e = foo(); |
| 593 | \\ const i = e catch 69; |
| 594 | \\ return i; |
| 595 | \\} |
| 596 | \\ |
| 597 | \\fn foo() anyerror!u32 { |
| 598 | \\ return error.Bruh; |
| 599 | \\} |
| 600 | , "69\n"); |
| 601 | } |
| 538 | 602 | } |