fail_not_exhaustive.carbon 780 B

1234567891011121314151617181920212223242526
  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 Opt {
  10. None(),
  11. Some(i32)
  12. }
  13. fn A(a: Opt, b: Opt) -> i32 {
  14. match ((a, b)) {
  15. case (Opt.Some(n: i32), _: auto) => { return n; }
  16. case (_: auto, Opt.Some(n: i32)) => { return n; }
  17. }
  18. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/match/fail_not_exhaustive.carbon:[[@LINE+1]]: non-exhaustive match may allow control-flow to reach the end of a function that provides a `->` return type
  19. }
  20. fn Main() -> i32 {
  21. return A(Opt.None(), Opt.Some(1));
  22. }