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
staticfunc s(_ unnamed:Int!, named:Int!)->Int!{return named }
9
+
10
+
init(_ value:Int){self.value = value }
11
+
init!(){returnnil}
12
+
13
+
subscript (
14
+
index:Int!
15
+
)->Int!{
16
+
return index
17
+
}
18
+
19
+
subscript<T>(
20
+
index:T!
21
+
)->T!{
22
+
return index
23
+
}
24
+
}
25
+
3
26
let _:ImplicitlyUnwrappedOptional<Int>=1 // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{8-36=}}{{39-39=!}}{{39-40=}}
4
27
let _:ImplicitlyUnwrappedOptional=1 // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' in unsupported; use an explicit type followed by '!'}}
5
28
6
29
extensionImplicitlyUnwrappedOptional{} // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
7
30
8
-
funcfunction(
31
+
funcfunctionSpelling(
9
32
_:ImplicitlyUnwrappedOptional<Int> // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{6-34=}}{{37-37=!}}{{37-38=}}
10
33
)->ImplicitlyUnwrappedOptional<Int>{ // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{6-34=}}{{37-37=!}}{{37-38=}}
11
34
return1
12
35
}
13
36
37
+
// Okay, like in the method case.
38
+
func functionSigil(
39
+
_:Int!
40
+
)->Int!{
41
+
return1
42
+
}
43
+
44
+
// Not okay because '!' is not at the top level of the type.
45
+
func functionSigilArray(
46
+
_:[Int!] // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
47
+
)->[Int!]{ // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
48
+
return[1]
49
+
}
50
+
14
51
func genericFunction<T>(
15
52
iuo:ImplicitlyUnwrappedOptional<T> // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{8-36=}}{{37-37=!}}{{37-38=}}
16
53
)->ImplicitlyUnwrappedOptional<T>{ // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{6-34=}}{{35-35=!}}{{35-36=}}
17
54
return iuo
18
55
}
19
56
57
+
// Okay, like in the non-generic case.
58
+
func genericFunctionSigil<T>(
59
+
iuo:T!
60
+
)->T!{
61
+
return iuo
62
+
}
63
+
64
+
func genericFunctionSigilArray<T>(
65
+
iuo:[T!] // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
66
+
)->[T!]{ // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
67
+
return iuo
68
+
}
69
+
20
70
protocolP{
21
71
associatedtypeT
22
72
associatedtypeU
@@ -26,11 +76,23 @@ struct S : P {
26
76
typealiasT=ImplicitlyUnwrappedOptional<Int> // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
27
77
typealiasU=Optional<ImplicitlyUnwrappedOptional<Int>> // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
28
78
79
+
typealiasV=Int! // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
80
+
typealiasW=Int!? // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
81
+
82
+
varx:V
83
+
vary:W
84
+
29
85
subscript (
30
86
index:ImplicitlyUnwrappedOptional<Int> // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{12-40=}}{{43-43=!}}{{43-44=}}
31
87
)->ImplicitlyUnwrappedOptional<Int>{ // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{12-40=}}{{43-43=!}}{{43-44=}}
32
88
return index
33
89
}
90
+
91
+
subscript<T>(
92
+
index:ImplicitlyUnwrappedOptional<T> // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{12-40=}}{{41-41=!}}{{41-42=}}
93
+
)->ImplicitlyUnwrappedOptional<T>{ // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{12-40=}}{{41-41=!}}{{41-42=}}
94
+
return index
95
+
}
34
96
}
35
97
36
98
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}}
@@ -45,16 +107,33 @@ func testClosure() -> Int {
45
107
}
46
108
47
109
_ = Array<Int!>() // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
110
+
let _:Array<Int!>=[1] // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
48
111
_ =[Int!]() // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
112
+
let _:[Int!]=[1] // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
49
113
_ = Optional<Int!>(nil) // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
114
+
let _:Optional<Int!>=nil // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
50
115
_ = Int!?(0) // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
116
+
let _:Int!?=0 // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
51
117
_ =(
52
118
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}}
119
+
Float!,
120
+
String!
55
121
)(1,2.0,"3")
122
+
let _:(
123
+
Int!, // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
124
+
Float!,
125
+
String!
126
+
)=(1,2.0,"3")
56
127
57
-
structGeneric<T, U, C>{}
128
+
structGeneric<T, U, C>{
129
+
init(_ t:T, _ u:U, _ c:C){}
130
+
}
58
131
_ = 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}}
132
+
Float!,
133
+
String!>(1,2.0,"3")
134
+
let _:Generic<Int!, // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
135
+
Float!,
136
+
String!>=Generic(1,2.0,"3")
137
+
138
+
func vararg(_ first:Int, more:Int!...){ // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
0 commit comments