I have a PolyType called tpe. I'd like to create a new type which is exactly the same as that type, but with each formal type parameter instantiated to Any. I thought that I could do this with:
> val actuals = List.fill(tpe.typeParams.length)(AnyClass.tpe)
> tpe.instantiateTypeParams(tpe.typeParams, actuals)
But the type I get back still seems to have the same typeParams :-(
For example, if I start with this:
> [A, B](x: Int, a: A, b: B)(Int, A, B)
After the above, I end up with:
> [A, B](x: Int, a: A, b: B)(Int, A, B)
But what I want to get is:
> (x: Int, a: Any, b: Any)(Int, Any, Any)
What am I missing?
Thanks in advance,
--
paul.butcher->msgCount++
Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?
http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: pa...@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher
It does do (a subset of) what applied type does - applied type calls it.
// this is the info for def f[A, B](x: Int, a: A, b: B): (Int, A, B)
scala> res0.info
res1: $r.intp.global.Type = [A<: <?>, B<: <?>](x: <?>, a: <?>, b:
<?>)(Int, A, B)
// This is you, trying to substitute into a polytype
scala> res0.info.instantiateTypeParams(res0.typeParams,
List(AnyClass.tpe, AnyClass.tpe))
res2: $r.intp.global.Type = [A, B](x: Int, a: A, b: B)(Int, A, B)
// This is applied type, substituting into a methodtype
scala> appliedType(res0.info, List(AnyClass.tpe, AnyClass.tpe))
res3: $r.intp.global.Type = (x: Int, a: Any, b: Any)(Int, Any, Any)
// This is you again after more closely imitating appliedType
scala> res0.info.resultType.instantiateTypeParams(res0.typeParams,
List(AnyClass.tpe, AnyClass.tpe))
res4: $r.intp.global.Type = (x: Int, a: Any, b: Any)(Int, Any, Any)
--