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