diff options
author | Martin Odersky <odersky@gmail.com> | 2014-07-16 22:30:31 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-07-17 11:02:03 +0200 |
commit | 491e07690dc2701d15544d0d77f0922180c45722 (patch) | |
tree | 1d0fb8dba44b0f9ab50d046a7979d34a18c10585 /src/dotty/tools/dotc/transform/FullParameterization.scala | |
parent | 7c56a5bb3d0b7902dbee6f11788e2d1033b20873 (diff) | |
download | dotty-491e07690dc2701d15544d0d77f0922180c45722.tar.gz dotty-491e07690dc2701d15544d0d77f0922180c45722.tar.bz2 dotty-491e07690dc2701d15544d0d77f0922180c45722.zip |
Handle selftypes in FullParameterization
Adapt the transformation so that self types are handled correctly.
Diffstat (limited to 'src/dotty/tools/dotc/transform/FullParameterization.scala')
-rw-r--r-- | src/dotty/tools/dotc/transform/FullParameterization.scala | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/transform/FullParameterization.scala b/src/dotty/tools/dotc/transform/FullParameterization.scala index 092e16086..a496716a5 100644 --- a/src/dotty/tools/dotc/transform/FullParameterization.scala +++ b/src/dotty/tools/dotc/transform/FullParameterization.scala @@ -71,6 +71,8 @@ trait FullParameterization { * object Foo { * def extension$baz[B >: A <: Any, A >: Nothing <: AnyRef]($this: Foo[A])(x: B): List[B] * } + * + * If a self type is present, $this has this self type as its type. */ def fullyParameterizedType(info: Type, clazz: ClassSymbol)(implicit ctx: Context): Type = { val (mtparamCount, origResult) = info match { @@ -81,11 +83,11 @@ trait FullParameterization { val ctparams = clazz.typeParams val ctnames = ctparams.map(_.name.unexpandedName()) - /** The method result type, prior to mapping any type parameters */ - val resultType = { - val thisParamType = clazz.typeRef.appliedTo(ctparams.map(_.typeRef)) + /** The method result type */ + def resultType(mapClassParams: Type => Type) = { + val thisParamType = mapClassParams(clazz.classInfo.selfType) MethodType(nme.SELF :: Nil, thisParamType :: Nil)(mt => - origResult.substThis(clazz, MethodParam(mt, 0))) + mapClassParams(origResult).substThis(clazz, MethodParam(mt, 0))) } /** Replace class type parameters by the added type parameters of the polytype `pt` */ @@ -98,17 +100,15 @@ trait FullParameterization { def mappedClassBounds(pt: PolyType): List[TypeBounds] = ctparams.map(tparam => mapClassParams(tparam.info, pt).bounds) - def mappedResultType(pt: PolyType): Type = mapClassParams(resultType, pt) - info match { case info @ PolyType(mtnames) => PolyType(mtnames ++ ctnames)( pt => (info.paramBounds ++ mappedClassBounds(pt)) .mapConserve(_.subst(info, pt).bounds), - pt => mappedResultType(pt).subst(info, pt)) + pt => resultType(mapClassParams(_, pt)).subst(info, pt)) case _ => - if (ctparams.isEmpty) resultType - else PolyType(ctnames)(mappedClassBounds, mappedResultType) + if (ctparams.isEmpty) resultType(identity) + else PolyType(ctnames)(mappedClassBounds, pt => resultType(mapClassParams(_, pt))) } } |