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/placeholder_type.swift
+78Lines changed: 78 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -122,6 +122,84 @@ let something: _! = getSomething()
122
122
123
123
extensionArraywhere Element ==Int{
124
124
staticvarstaticMember:Self{[]}
125
+
staticfunc staticFunc()->Self{[]}
126
+
127
+
varmember:Self{[]}
128
+
func method()->Self{[]}
129
+
}
130
+
131
+
extensionArray{
132
+
staticvarotherStaticMember:Self{[]}
125
133
}
126
134
127
135
let _ =[_].staticMember
136
+
let _ =[_].staticFunc()
137
+
let _ =[_].otherStaticMember.member
138
+
let _ =[_].otherStaticMember.method()
139
+
140
+
func f(x:Any, arr:[Int]){
141
+
// FIXME: Better diagnostics here. Maybe we should suggest replacing placeholders with 'Any'?
142
+
143
+
if x is _{} // expected-error {{type of expression is ambiguous without more context}}
144
+
if x is [_]{} // expected-error {{type of expression is ambiguous without more context}}
145
+
if x is ()->_{} // expected-error {{type of expression is ambiguous without more context}}
146
+
iflet y = x as?_{} // expected-error {{type of expression is ambiguous without more context}}
147
+
iflet y = x as?[_]{} // expected-error {{type of expression is ambiguous without more context}}
148
+
iflet y = x as?()->_{} // expected-error {{type of expression is ambiguous without more context}}
149
+
lety1= x as!_ // expected-error {{type of expression is ambiguous without more context}}
150
+
lety2= x as![_] // expected-error {{type of expression is ambiguous without more context}}
151
+
lety3= x as!()->_ // expected-error {{type of expression is ambiguous without more context}}
152
+
153
+
switch x {
154
+
case is _:break // expected-error {{placeholder type not allowed here}}
155
+
case is [_]:break // expected-error {{placeholder type not allowed here}}
156
+
case is ()->_:break // expected-error {{placeholder type not allowed here}}
157
+
caselety as _:break // expected-error {{placeholder type not allowed here}}
158
+
caselety as [_]:break // expected-error {{placeholder type not allowed here}}
159
+
caselety as ()->_:break // expected-error {{placeholder type not allowed here}}
160
+
}
161
+
162
+
if arr is _{} // expected-error {{type of expression is ambiguous without more context}}
163
+
if arr is [_]{} // expected-error {{type of expression is ambiguous without more context}}
164
+
if arr is ()->_{} // expected-error {{type of expression is ambiguous without more context}}
165
+
iflet y = arr as?_{} // expected-error {{type of expression is ambiguous without more context}}
166
+
iflet y = arr as?[_]{} // expected-error {{type of expression is ambiguous without more context}}
167
+
iflet y = arr as?()->_{} // expected-error {{type of expression is ambiguous without more context}}
168
+
lety1= arr as!_ // expected-error {{type of expression is ambiguous without more context}}
169
+
lety2= arr as![_] // expected-error {{type of expression is ambiguous without more context}}
170
+
lety3= arr as!()->_ // expected-error {{type of expression is ambiguous without more context}}
171
+
172
+
switch arr {
173
+
case is _:break // expected-error {{placeholder type not allowed here}}
174
+
case is [_]:break // expected-error {{placeholder type not allowed here}}
175
+
case is ()->_:break // expected-error {{placeholder type not allowed here}}
176
+
caselety as _:break // expected-error {{placeholder type not allowed here}}
177
+
caselety as [_]:break // expected-error {{placeholder type not allowed here}}
178
+
caselety as ()->_:break // expected-error {{placeholder type not allowed here}}
179
+
}
180
+
}
181
+
182
+
protocolPublisher{
183
+
associatedtypeOutput
184
+
associatedtypeFailure
185
+
}
186
+
187
+
structJust<Output>:Publisher{
188
+
typealiasFailure=Never
189
+
}
190
+
191
+
structSetFailureType<Output, Failure>:Publisher{}
192
+
193
+
extensionPublisher{
194
+
func setFailureType<T>(to:T.Type)->SetFailureType<Output,T>{ // expected-note {{in call to function 'setFailureType(to:)'}}
195
+
return.init()
196
+
}
197
+
}
198
+
199
+
let _:SetFailureType<Int,String>=Just<Int>().setFailureType(to: _.self)
200
+
let _:SetFailureType<Int,[String]>=Just<Int>().setFailureType(to:[_].self)
201
+
let _:SetFailureType<Int,(String)->Double>=Just<Int>().setFailureType(to:((_)-> _).self)
202
+
let _:SetFailureType<Int,(String,Double)>=Just<Int>().setFailureType(to:(_, _).self)
203
+
204
+
// TODO: Better error message here? Would be nice if we could point to the placeholder...
205
+
let _:SetFailureType<Int,String>=Just<Int>().setFailureType(to: _.self).setFailureType(to:String.self) // expected-error {{generic parameter 'T' could not be inferred}}
0 commit comments