@@ -290,8 +290,9 @@ class TypeApplications(val self: Type) extends AnyVal {
290
290
/** If this is an encoding of a (partially) applied type, return its arguments,
291
291
* otherwise return Nil.
292
292
* Existential types in arguments are returned as TypeBounds instances.
293
+ * @param interpolate See argInfo
293
294
*/
294
- final def argInfos (implicit ctx : Context ): List [Type ] = {
295
+ final def argInfos (interpolate : Boolean )( implicit ctx : Context ): List [Type ] = {
295
296
var tparams : List [TypeSymbol ] = null
296
297
def recur (tp : Type , refineCount : Int ): mutable.ListBuffer [Type ] = tp.stripTypeVar match {
297
298
case tp @ RefinedType (tycon, name) =>
@@ -301,7 +302,7 @@ class TypeApplications(val self: Type) extends AnyVal {
301
302
if (tparams == null ) tparams = tycon.typeParams
302
303
if (buf.size < tparams.length) {
303
304
val tparam = tparams(buf.size)
304
- if (name == tparam.name) buf += tp.refinedInfo.argInfo(tparam)
305
+ if (name == tparam.name) buf += tp.refinedInfo.argInfo(tparam, interpolate )
305
306
else null
306
307
} else null
307
308
}
@@ -313,6 +314,8 @@ class TypeApplications(val self: Type) extends AnyVal {
313
314
if (buf == null ) Nil else buf.toList
314
315
}
315
316
317
+ final def argInfos (implicit ctx : Context ): List [Type ] = argInfos(interpolate = true )
318
+
316
319
/** Argument types where existential types in arguments are disallowed */
317
320
def argTypes (implicit ctx : Context ) = argInfos mapConserve noBounds
318
321
@@ -335,16 +338,27 @@ class TypeApplications(val self: Type) extends AnyVal {
335
338
336
339
/** If this is the image of a type argument to type parameter `tparam`,
337
340
* recover the type argument, otherwise NoType.
341
+ * @param interpolate If true, replace type bounds as arguments corresponding to
342
+ * variant type parameters by their dominating element. I.e. an argument
343
+ *
344
+ * T <: U
345
+ *
346
+ * for a covariant type-parameter becomes U, and an argument
347
+ *
348
+ * T >: L
349
+ *
350
+ * for a contravariant type-parameter becomes L.
338
351
*/
339
- final def argInfo (tparam : Symbol )(implicit ctx : Context ): Type = self match {
352
+ final def argInfo (tparam : Symbol , interpolate : Boolean = true )(implicit ctx : Context ): Type = self match {
340
353
case TypeBounds (lo, hi) =>
341
354
if (lo eq hi) hi
342
- else {
355
+ else if (interpolate) {
343
356
val v = tparam.variance
344
357
if (v > 0 && (lo isRef defn.NothingClass )) hi
345
358
else if (v < 0 && (hi isRef defn.AnyClass )) lo
346
- else self // it's wildcard type; return its bounds
359
+ else self
347
360
}
361
+ else self
348
362
case _ =>
349
363
NoType
350
364
}
0 commit comments