From a9aa810472b5ee117b0865350a06b28a06b27c5c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 21 Jul 2014 18:41:52 +0200 Subject: [PATCH] Fix of FullParameterization Avoid substitituting A.this if A is a globally accesisble mdoule. --- src/dotty/tools/dotc/core/Types.scala | 4 ++++ src/dotty/tools/dotc/transform/FullParameterization.scala | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 289515ae1c05..85211fca5110 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -832,6 +832,10 @@ object Types { final def substThis(cls: ClassSymbol, tp: Type)(implicit ctx: Context): Type = ctx.substThis(this, cls, tp, null) + /** As substThis, but only is class is a static owner (i.e. a globally accessible object) */ + final def substThisUnlessStatic(cls: ClassSymbol, tp: Type)(implicit ctx: Context): Type = + if (cls.isStaticOwner) this else ctx.substThis(this, cls, tp, null) + /** Substitute all occurrences of `RefinedThis(rt)` by `tp` */ final def substThis(rt: RefinedType, tp: Type)(implicit ctx: Context): Type = ctx.substThis(this, rt, tp, null) diff --git a/src/dotty/tools/dotc/transform/FullParameterization.scala b/src/dotty/tools/dotc/transform/FullParameterization.scala index fea0482a0d01..e21a10492f4f 100644 --- a/src/dotty/tools/dotc/transform/FullParameterization.scala +++ b/src/dotty/tools/dotc/transform/FullParameterization.scala @@ -98,7 +98,7 @@ trait FullParameterization { def resultType(mapClassParams: Type => Type) = { val thisParamType = mapClassParams(clazz.classInfo.selfType) MethodType(nme.SELF :: Nil, thisParamType :: Nil)(mt => - mapClassParams(origResult).substThis(clazz, MethodParam(mt, 0))) + mapClassParams(origResult).substThisUnlessStatic(clazz, MethodParam(mt, 0))) } /** Replace class type parameters by the added type parameters of the polytype `pt` */ @@ -203,7 +203,7 @@ trait FullParameterization { typeMap = rewireType(_) .subst(origTParams, trefs) .subst(origVParams, argRefs.map(_.tpe)) - .substThis(origClass, thisRef.tpe), + .substThisUnlessStatic(origClass, thisRef.tpe), ownerMap = (sym => if (sym eq origMeth) derived else sym), treeMap = { case tree: This if tree.symbol == origClass => thisRef