fail_not_exhaustive.carbon 683 B

123456789101112131415161718192021222324
  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. // NOAUTOUPDATE
  6. package ExplorerTest api;
  7. choice Opt {
  8. None(),
  9. Some(i32)
  10. }
  11. fn A(a: Opt, b: Opt) -> i32 {
  12. match ((a, b)) {
  13. case (Opt.Some(n: i32), _: auto) => { return n; }
  14. case (_: auto, Opt.Some(n: i32)) => { return n; }
  15. }
  16. // CHECK:STDERR: COMPILATION ERROR: 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
  17. }
  18. fn Main() -> i32 {
  19. return A(Opt.None(), Opt.Some(1));
  20. }