738e3314d89604cb56233d3d1d985b895264250f 832 B

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