exhaustive.carbon 886 B

1234567891011121314151617181920212223242526272829303132333435
  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. // AUTOUPDATE
  6. // RUN: %{explorer-run}
  7. // RUN: %{explorer-run-trace}
  8. // CHECK:STDOUT: result: 3
  9. package ExplorerTest api;
  10. choice Opt {
  11. None(),
  12. Some(i32)
  13. }
  14. fn A(a: Opt, b: Opt) -> i32 {
  15. match ((a, b)) {
  16. case (Opt.Some(n: i32), _: auto) => { return n; }
  17. case (_: auto, Opt.Some(n: i32)) => { return n; }
  18. case (Opt.None(), Opt.None()) => { return 0; }
  19. }
  20. }
  21. fn B(a: Opt, b: Opt) -> i32 {
  22. match ((a, b)) {
  23. case (Opt.None(), _: auto) => { return 0; }
  24. case (Opt.Some(n: i32), Opt.None()) => { return n; }
  25. case (Opt.Some(n: i32), Opt.Some(m: i32)) => { return n + m; }
  26. }
  27. }
  28. fn Main() -> i32 {
  29. return A(Opt.None(), Opt.Some(1)) + B(Opt.Some(2), Opt.None());
  30. }