choice1.6c 766 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. choice Ints {
  5. None,
  6. One(Int),
  7. Two(Int,Int)
  8. }
  9. fn main() -> Int {
  10. var auto: x = Ints.None();
  11. var auto: y = Ints.One(42);
  12. var auto: n = 0;
  13. match (y) {
  14. case Ints.None =>
  15. n = n + 2;
  16. case Ints.One(auto: x) =>
  17. n = x + 1 - 42;
  18. case Ints.Two(auto: a, auto: b) =>
  19. n = 2;
  20. }
  21. match (x) {
  22. case Ints.One(auto: x) =>
  23. n = x + 2;
  24. case Ints.None() =>
  25. n = n - 1;
  26. case Ints.Two(auto: x, auto: y) =>
  27. n = 5;
  28. }
  29. return n;
  30. }
  31. // Test some alternate syntaxes
  32. choice MoreInts {
  33. None(),
  34. One(Int),
  35. Two(Int,Int),
  36. }