generic_choice_simple_assignment.carbon 533 B

123456789101112131415161718192021222324252627
  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. package ExplorerTest api;
  7. choice MyOptionalElement(ZZ:! type) {
  8. None(ZZ),
  9. Element(ZZ)
  10. }
  11. fn Main() -> i32 {
  12. var f: MyOptionalElement(i32);
  13. f = MyOptionalElement(i32).None(22);
  14. match(f) {
  15. case MyOptionalElement(i32).None(var x: i32) => {
  16. return x;
  17. }
  18. }
  19. return 0;
  20. }
  21. // CHECK:STDOUT: result: 22