generic_choice_simple_assignment.carbon 532 B

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