From 5c2004c0740fc2bf31bbd752891d646823437aed Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Tue, 7 Nov 2006 12:56:53 +0000 Subject: Fixed bug #799: the super accessors were iterat... Fixed bug #799: the super accessors were iterating over class parents, which is not necessary. --- .../tools/nsc/transform/TypingTransformers.scala | 2 +- .../tools/nsc/typechecker/SuperAccessors.scala | 48 ++++++++++++++++++---- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala b/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala index c5ff08a548..b16c8aed13 100644 --- a/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala +++ b/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala @@ -19,7 +19,7 @@ trait TypingTransformers { abstract class TypingTransformer(unit: CompilationUnit) extends Transformer { var localTyper: analyzer.Typer = analyzer.newTyper( analyzer.rootContext(unit, EmptyTree, true)) - private var curTree: Tree = _ + protected var curTree: Tree = _ /** a typer for each enclosing class */ var typers: Map[Symbol, analyzer.Typer] = new HashMap diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 91d5855ac0..1e7244e8d2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -64,8 +64,13 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT case Template(parents, body) => val ownAccDefs = new ListBuffer[Tree]; accDefs = Pair(currentOwner, ownAccDefs) :: accDefs; -// val body1 = transformTrees(body); - val Template(_, body1) = super.transform(tree); + + // ugly hack... normally, the following line should not be + // necessary, the 'super' method taking care of that. but because + // that one is iterating through parents (and we dont want that here) + // we need to inline it. + curTree = tree + val body1 = atOwner(currentOwner) { transformTrees(body) } accDefs = accDefs.tail; copy.Template(tree, parents, ownAccDefs.toList ::: body1); @@ -175,16 +180,28 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT val hasArgs = sym.tpe.paramTypes != Nil if (protAcc == NoSymbol) { val resTpe = tree.tpe + val argTypes = + if (hasArgs) + MethodType( + sym.tpe.paramTypes map {t => +// Console.print("Transforming " + t + "(sym=" + t.symbol +") to ") +// Console.println("" + clazz.typeOfThis + ".memberType = " + clazz.typeOfThis.memberType(t.symbol)) + + if (!t.symbol.isAbstractType || t.symbol.isTypeParameter) + clazz.typeOfThis.memberType(t.symbol) + else + t + }, + resTpe.resultType /*sym.tpe.resultType*/) + else + resTpe.resultType /*sym.tpe.resultType*/ + protAcc = clazz.newMethod(tree.pos, nme.protName(sym.originalName)) - .setInfo(MethodType(List(clazz.typeOfThis), - if (hasArgs) - MethodType(sym.tpe.paramTypes, resTpe.resultType /*sym.tpe.resultType*/) - else - resTpe.resultType /*sym.tpe.resultType*/)) + .setInfo(MethodType(List(clazz.typeOfThis),argTypes)) clazz.info.decls.enter(protAcc); val code = DefDef(protAcc, vparamss => vparamss.tail.foldRight(Select(gen.mkAttributedRef(vparamss.head.head), sym): Tree) ( - (vparams, fun) => Apply(fun, (vparams map { v => Ident(v) } )))) + (vparams, fun) => Apply(fun, (vparams map { v => makeArg(v, vparamss.head.head) } )))) if (settings.debug.value) log(code) accDefBuf(clazz) += typers(clazz).typed(code) @@ -195,6 +212,21 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT if (hasArgs) typer.typedOperator(res) else typer.typed(res) } + private def makeArg(v: Symbol, obj: Symbol): Tree = { +// Console.println("" + v + ".tpe = " + v.tpe + " .symbol = " +// + v.tpe.symbol + " isAbstractType = " + v.tpe.symbol.isAbstractType); + val res = Ident(v) + + if (v.tpe.symbol.isAbstractType && !v.tpe.symbol.isTypeParameter) { + val preciseTpe = typeRef(singleType(NoPrefix, obj), v.tpe.symbol, List()) + Console.println("precise tpe: " + preciseTpe) + TypeApply(Select(res, definitions.Any_asInstanceOf), + List(TypeTree(preciseTpe))) + } + else + res + } + /** Add an accessor for field, if needed, and return a selection tree for it . * The result is not typed. */ -- cgit v1.2.3