fail_not_reachable.carbon 1.0 KB

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