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