fail_match_choice.carbon 951 B

1234567891011121314151617181920212223242526272829303132333435
  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. // RUN: %{not} %{explorer} %s 2>&1 | \
  6. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s
  7. // RUN: %{not} %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
  8. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
  9. // AUTOUPDATE: %{explorer} %s
  10. package ExplorerTest api;
  11. choice Ints {
  12. None,
  13. One(i32),
  14. Two(i32, i32)
  15. }
  16. fn Main() -> i32 {
  17. var x: auto = Ints.None();
  18. var n: auto = 0;
  19. match (x) {
  20. case Ints.One(var x: auto) => {
  21. x = 2;
  22. }
  23. case Ints.None() => {
  24. n = n - 1;
  25. }
  26. case Ints.Two(x: auto, y: auto) => {
  27. // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/let/fail_match_choice.carbon:[[@LINE+1]]: Cannot assign to rvalue 'x'
  28. x = 0;
  29. }
  30. }
  31. return 0;
  32. }