fail_not_reachable_default.carbon 1.0 KB

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. // 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 Opt {
  12. None(),
  13. Some(i32)
  14. }
  15. fn A(a: Opt, b: Opt) -> i32 {
  16. match ((a, b)) {
  17. case (Opt.None(), Opt.None()) => { return 0; }
  18. case (Opt.Some(n: i32), _: auto) => { return n; }
  19. case (_: auto, Opt.Some(n: i32)) => { return n; }
  20. // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/match/fail_not_reachable_default.carbon:[[@LINE+1]]: unreachable case: all values matched by this case are matched by earlier cases
  21. default => { return -1; }
  22. }
  23. return 0;
  24. }
  25. fn Main() -> i32 {
  26. return A(Opt.None(), Opt.Some(1));
  27. }