You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/Sema/package_resilience_bypass_exhaustive_switch.swift
+34-11Lines changed: 34 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -35,10 +35,16 @@ public enum FrozenPublicEnum {
35
35
case two(Int)
36
36
}
37
37
38
+
@usableFromInline
39
+
enumUfiInternalEnum{
40
+
case one
41
+
case two(Int)
42
+
}
43
+
38
44
//--- ClientDefault.swift
39
45
import Utils
40
46
41
-
func f(_ arg:PkgEnum)->Int{
47
+
packagefunc f(_ arg:PkgEnum)->Int{
42
48
switch arg { // expected-warning {{switch covers known cases, but 'PkgEnum' may have additional unknown values}} {{none}} expected-note {{handle unknown values using "@unknown default"}}
43
49
case.one:
44
50
return1
@@ -47,7 +53,7 @@ func f(_ arg: PkgEnum) -> Int {
47
53
}
48
54
}
49
55
50
-
func g(_ arg:UfiPkgEnum)->Int{
56
+
publicfunc g(_ arg:UfiPkgEnum)->Int{
51
57
switch arg { // expected-warning {{switch covers known cases, but 'UfiPkgEnum' may have additional unknown values}} {{none}} expected-note {{handle unknown values using "@unknown default"}}
52
58
case.one:
53
59
return1
@@ -74,33 +80,41 @@ public func k(_ arg: FrozenPublicEnum) -> Int {
74
80
}
75
81
}
76
82
83
+
publicfunc m(_ arg:UfiInternalEnum)->Int{
84
+
switch arg { // no-warning
85
+
case.one:
86
+
return1
87
+
case.two(let val):
88
+
return2+ val
89
+
}
90
+
}
91
+
77
92
//--- ClientOptimized.swift
78
93
import Utils
79
94
80
-
// No warning with optimization to bypass resilience checks for package enums.
81
-
func f(_ arg:PkgEnum)->Int{
82
-
switch arg {
95
+
// With optimization enabled to bypass resilience checks within
96
+
// a package boundary, public (non-frozen) or package enums no
97
+
// longer require `@unknown default` in source code switch stmts.
98
+
packagefunc f(_ arg:PkgEnum)->Int{
99
+
switch arg { // no-warning
83
100
case.one:
84
101
return1
85
102
case.two(let val):
86
103
return2+ val
87
104
}
88
105
}
89
106
90
-
// Warning still shows up for usableFromInline package enum as the optimization is targeted for
91
-
// decls with package access, not the elevated public access. This might be allowed later.
92
-
func g(_ arg:UfiPkgEnum)->Int{
93
-
switch arg { // expected-warning {{switch covers known cases, but 'UfiPkgEnum' may have additional unknown values}} {{none}} expected-note {{handle unknown values using "@unknown default"}}
107
+
publicfunc g(_ arg:UfiPkgEnum)->Int{
108
+
switch arg { // no-warning
94
109
case.one:
95
110
return1
96
111
case.two(let val):
97
112
return2+ val
98
113
}
99
114
}
100
115
101
-
// Warning still shows up for public enum as the optimization is targeted for package types.
102
116
publicfunc h(_ arg:PublicEnum)->Int{
103
-
switch arg { // expected-warning {{switch covers known cases, but 'PublicEnum' may have additional unknown values}} {{none}} expected-note {{handle unknown values using "@unknown default"}}
117
+
switch arg { // no-warning
104
118
case.one:
105
119
return1
106
120
case.two(let val):
@@ -116,3 +130,12 @@ public func k(_ arg: FrozenPublicEnum) -> Int {
0 commit comments