exhaustive.carbon 835 B

12345678910111213141516171819202122232425262728293031323334
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // NOAUTOUPDATE
  6. package ExplorerTest api;
  7. choice Opt {
  8. None(),
  9. Some(i32)
  10. }
  11. fn A(a: Opt, b: Opt) -> i32 {
  12. match ((a, b)) {
  13. case (Opt.Some(n: i32), _: auto) => { return n; }
  14. case (_: auto, Opt.Some(n: i32)) => { return n; }
  15. case (Opt.None(), Opt.None()) => { return 0; }
  16. }
  17. }
  18. fn B(a: Opt, b: Opt) -> i32 {
  19. match ((a, b)) {
  20. case (Opt.None(), _: auto) => { return 0; }
  21. case (Opt.Some(n: i32), Opt.None()) => { return n; }
  22. case (Opt.Some(n: i32), Opt.Some(m: i32)) => { return n + m; }
  23. }
  24. }
  25. fn Main() -> i32 {
  26. return A(Opt.None(), Opt.Some(1)) + B(Opt.Some(2), Opt.None());
  27. }
  28. // CHECK:STDOUT: result: 3