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