summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2006-11-07 12:56:53 +0000
committerIulian Dragos <jaguarul@gmail.com>2006-11-07 12:56:53 +0000
commit5c2004c0740fc2bf31bbd752891d646823437aed (patch)
tree8a09367cc1b4df41cb7fc40574a3f38564b2eb90
parent84089c19ec1707d3fa3e37c6218cb990013d4066 (diff)
downloadscala-5c2004c0740fc2bf31bbd752891d646823437aed.tar.gz
scala-5c2004c0740fc2bf31bbd752891d646823437aed.tar.bz2
scala-5c2004c0740fc2bf31bbd752891d646823437aed.zip
Fixed bug #799: the super accessors were iterat...
Fixed bug #799: the super accessors were iterating over class parents, which is not necessary.
-rw-r--r--src/compiler/scala/tools/nsc/transform/TypingTransformers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala48
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.
*/