File: exhaustive_switch_invocation_threshold.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (51 lines) | stat: -rw-r--r-- 1,330 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Ensure that -switch-checking-invocation-threshold= frontend option works,
// stopping the check, producing the correct diagnostic, and not producing the
// diagnostic for a completed check.
//
// RUN: %empty-directory(%t)
//
// RUN: not %target-swift-frontend -typecheck %s -switch-checking-invocation-threshold=1 2>%t/unproven.txt
// RUN: %FileCheck %s --check-prefix UNABLE-TO-CHECK <%t/unproven.txt
// RUN: not %FileCheck %s --check-prefix MUST-BE-EXHAUSTIVE <%t/unproven.txt
//
// RUN: not %target-swift-frontend -typecheck %s  2>%t/disproved.txt
// RUN: %FileCheck %s --check-prefix MUST-BE-EXHAUSTIVE <%t/disproved.txt
// RUN: not %FileCheck %s --check-prefix UNABLE-TO-CHECK <%t/disproved.txt
//
// UNABLE-TO-CHECK: error: the compiler is unable to check that this switch is exhaustive in reasonable time
// MUST-BE-EXHAUSTIVE: error: switch must be exhaustive


enum A {
  case a1, a2, a3, a4, a5
}
enum B {
  case b1, b2, b3, b4
}

func f(a: A, b: B) {
  switch (a, b) {
    case
//    (.a1, .b1),
    (.a2, .b1),
    (.a3, .b1),
    (.a4, .b1),
    (.a5, .b1),
    (.a1, .b2),
    (.a2, .b2),
    (.a3, .b2),
    (.a4, .b2),
    (.a5, .b2),
    (.a1, .b3),
    (.a2, .b3),
    (.a3, .b3),
    (.a4, .b3),
    (.a5, .b3),
    (.a1, .b4),
    (.a2, .b4),
    (.a3, .b4),
    (.a4, .b4),
    (.a5, .b4):
    break
  }
}