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
Suggest Replacement Types for Invalid Placeholders
Now that placeholder types are preserved, we can open them wherever they appear in positions where they are used as contextual types. Use the checks we already run in the primaries to ban placeholders in top-level positions. Only now, use the inferred type of any associated expressions or statements to present the user with a contextual return type.
For parameters in functions and enum cases, we use any default argument expressions to get the contextual type.
For functions, we use a traversal similar to the opaque result type finder to find the type of any return statements in the program and present those as options.
let _:SetFailureType<Int,(String,Double)>=Just<Int>().setFailureType(to:(_, _).self)
198
207
199
208
// TODO: Better error message here? Would be nice if we could point to the placeholder...
200
-
let _:SetFailureType<Int,String>=Just<Int>().setFailureType(to: _.self).setFailureType(to:String.self) // expected-error {{placeholders are not allowed as top-level types}}
209
+
let _:SetFailureType<Int,String>=Just<Int>().setFailureType(to: _.self).setFailureType(to:String.self) // expected-error {{generic parameter 'T' could not be inferred}}
201
210
202
-
let _:(_)=0asInt // expected-error {{placeholders are not allowed as top-level types}}
203
-
let _:Int=0as(_) // expected-error {{placeholders are not allowed as top-level types}}
211
+
let _:(_)=0asInt
212
+
let _:Int=0as(_)
204
213
205
214
_ =(1...10)
206
215
.map{
@@ -217,3 +226,31 @@ _ = (1...10)
217
226
}
218
227
219
228
let _:SetFailureType<Int,String>=Just<Int>().setFailureType(to: _.self).setFailureType(to:String.self) // expected-error {{generic parameter 'T' could not be inferred}}
229
+
230
+
// N.B. The parallel structure of the annotation and inferred default
231
+
// initializer types is all wrong. Plus, we do not trust
232
+
// the contextual type with placeholders in it so the result is a generic
0 commit comments