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
Ban IUOs in illegal positions harder under Swift 5 and later.
SE-0054 specified that the use of implicitly unwrapped optionals was
limited to just a few places, but the implementation at the time did not
completely ban the other uses. This is another attempt to do so, but
it's only on for compilations in Swift 5 mode and later.
For earlier versions, we fall back on the existing implementation.
Fixes: rdar://problem/27707015
let _:ImplicitlyUnwrappedOptional<Int>=1 // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{8-36=}}{{39-39=!}}{{39-40=}}
4
+
let _:ImplicitlyUnwrappedOptional=1 // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' in unsupported; use an explicit type followed by '!'}}
5
+
6
+
extensionImplicitlyUnwrappedOptional{} // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
7
+
8
+
func function(
9
+
_:ImplicitlyUnwrappedOptional<Int> // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{6-34=}}{{37-37=!}}{{37-38=}}
10
+
)->ImplicitlyUnwrappedOptional<Int>{ // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{6-34=}}{{37-37=!}}{{37-38=}}
11
+
return1
12
+
}
13
+
14
+
func genericFunction<T>(
15
+
iuo:ImplicitlyUnwrappedOptional<T> // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{8-36=}}{{37-37=!}}{{37-38=}}
16
+
)->ImplicitlyUnwrappedOptional<T>{ // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{6-34=}}{{35-35=!}}{{35-36=}}
17
+
return iuo
18
+
}
19
+
20
+
protocolP{
21
+
associatedtypeT
22
+
associatedtypeU
23
+
}
24
+
25
+
structS:P{
26
+
typealiasT=ImplicitlyUnwrappedOptional<Int> // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
27
+
typealiasU=Optional<ImplicitlyUnwrappedOptional<Int>> // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
28
+
29
+
subscript (
30
+
index:ImplicitlyUnwrappedOptional<Int> // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{12-40=}}{{43-43=!}}{{43-44=}}
31
+
)->ImplicitlyUnwrappedOptional<Int>{ // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{12-40=}}{{43-43=!}}{{43-44=}}
32
+
return index
33
+
}
34
+
}
35
+
36
+
func generic<T :P>(_:T)where T.T ==ImplicitlyUnwrappedOptional<Int>{} // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
37
+
func genericOptIUO<T :P>(_:T)where T.U ==Optional<ImplicitlyUnwrappedOptional<Int>>{} // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
38
+
39
+
func testClosure()->Int{
40
+
return{
41
+
(i:ImplicitlyUnwrappedOptional<Int>) // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{9-37=}}{{40-40=!}}{{40-41=}}
42
+
->ImplicitlyUnwrappedOptional<Int>in // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
43
+
return i
44
+
}(1)
45
+
}
46
+
47
+
_ = Array<Int!>() // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
48
+
_ =[Int!]() // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
49
+
_ = Optional<Int!>(nil) // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
50
+
_ = Int!?(0) // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
51
+
_ =(
52
+
Int!, // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
53
+
Float!, // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
54
+
String! // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
55
+
)(1,2.0,"3")
56
+
57
+
structGeneric<T, U, C>{}
58
+
_ = Generic<Int!, // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
59
+
Float!, // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
60
+
String!>() // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
0 commit comments