fail_match_choice.carbon 689 B

12345678910111213141516171819202122232425262728293031
  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 Ints {
  8. None,
  9. One(i32),
  10. Two(i32, i32)
  11. }
  12. fn Main() -> i32 {
  13. var x: auto = Ints.None;
  14. var n: auto = 0;
  15. match (x) {
  16. case Ints.One(var x: auto) => {
  17. x = 2;
  18. }
  19. case Ints.None => {
  20. n = n - 1;
  21. }
  22. case Ints.Two(x: auto, y: auto) => {
  23. // CHECK:STDERR: COMPILATION ERROR: fail_match_choice.carbon:[[@LINE+1]]: Only a reference expression can be assigned to, but got `x`
  24. x = 0;
  25. }
  26. }
  27. return 0;
  28. }