diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala | 9 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 11 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala index a94e9e7dc2..455eb1d3b1 100644 --- a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala +++ b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala @@ -89,7 +89,7 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { MethodType(List(thisParam), restpe) } val GenPolyType(tparams, restpe) = origInfo cloneInfo extensionMeth - GenPolyType(tparams ::: newTypeParams, transform(restpe)) + GenPolyType(tparams ::: newTypeParams, transform(restpe) substSym (clazz.typeParams, newTypeParams)) } private def allParams(tpe: Type): List[Symbol] = tpe match { @@ -103,8 +103,9 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { if (currentOwner.isDerivedValueClass) { extensionDefs(currentOwner.companionModule) = new mutable.ListBuffer[Tree] super.transform(tree) - } - else tree + } else if (currentOwner.isStaticOwner) { + super.transform(tree) + } else tree case DefDef(mods, name, tparams, vparamss, tpt, rhs) if tree.symbol.isMethodWithExtension => val companion = currentOwner.companionModule val origMeth = tree.symbol @@ -121,7 +122,7 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { def thisParamRef = gen.mkAttributedIdent(extensionMeth.info.params.head setPos extensionMeth.pos) val GenPolyType(extensionTpeParams, extensionMono) = extensionMeth.info - val origTpeParams = origMeth.typeParams ::: currentOwner.typeParams + val origTpeParams = (tparams map (_.symbol)) ::: currentOwner.typeParams val extensionBody = rhs .substTreeSyms(origTpeParams, extensionTpeParams) .substTreeSyms(vparamss.flatten map (_.symbol), allParams(extensionMono).tail) diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 9027b6039c..5207fe8331 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -73,7 +73,7 @@ trait Namers extends MethodSynthesis { classAndNamerOfModule.clear() } - abstract class Namer(val context: Context) extends MethodSynth with NamerContextErrors { + abstract class Namer(val context: Context) extends MethodSynth with NamerContextErrors { thisNamer => import NamerErrorGen._ val typer = newTyper(context) @@ -99,6 +99,13 @@ trait Namers extends MethodSynthesis { owner.unsafeTypeParams foreach (paramContext.scope enter _) newNamer(paramContext) } + + def enclosingNamerWithScope(scope: Scope) = { + var cx = context + while (cx != NoContext && cx.scope != scope) cx = cx.outer + if (cx == context) thisNamer + else newNamer(cx) + } def enterValueParams(vparamss: List[List[ValDef]]): List[List[Symbol]] = { mmap(vparamss) { param => @@ -1265,7 +1272,7 @@ trait Namers extends MethodSynthesis { clazz setInfo result if (clazz.isDerivedValueClass) { clazz setFlag FINAL - ensureCompanionObject(cdef) + enclosingNamerWithScope(clazz.owner.info.decls).ensureCompanionObject(cdef) } result |