summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-02-21 17:14:36 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-02-21 17:14:36 +0000
commit3621100820d0541e4863ceed8523b887894069e1 (patch)
tree4d7ab86554a5b0b86babc4262e3ac2ea31f5bad1 /src
parent3594304e825f6cd255a1cf61807dd3408ab3b5da (diff)
downloadscala-3621100820d0541e4863ceed8523b887894069e1.tar.gz
scala-3621100820d0541e4863ceed8523b887894069e1.tar.bz2
scala-3621100820d0541e4863ceed8523b887894069e1.zip
Fixed a bug where newly introduced type paramet...
Fixed a bug where newly introduced type parameters didn't have all the substitutions done correctly. Fixes #4266. No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala13
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Duplicators.scala28
2 files changed, 36 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
index ceeac9d5a5..cfbc387ef6 100644
--- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
+++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
@@ -445,10 +445,12 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
*/
def produceTypeParameters(syms: List[Symbol], nowner: Symbol, env: TypeEnv) = {
val cloned = for (s <- syms) yield if (!env.contains(s)) s.cloneSymbol(nowner) else env(s).typeSymbol
+ // log("producing type params: " + cloned.map(t => (t, t.tpe.bounds.hi)))
for ((orig, cln) <- syms zip cloned) {
cln.removeAnnotation(SpecializedClass)
if (env.contains(orig)) cln.setInfo(TypeBounds(cln.info.bounds.lo, AnyRefClass.tpe))
}
+ for (sym <- cloned) sym.setInfo(sym.info.substSym(syms, cloned))
cloned
}
@@ -506,7 +508,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
val survivedParams = survivingParams(clazz.info.typeParams, env)
oldClassTParams = survivedParams
newClassTParams = produceTypeParameters(survivedParams, cls, env) map subst(env)
- log("new tparams " + newClassTParams.zip(newClassTParams map {_.tpe}))
+ // log("new tparams " + newClassTParams.zip(newClassTParams map {s => (s.tpe, s.tpe.bounds.hi)}) + ", in env: " + env)
def applyContext(tpe: Type) =
subst(env, tpe).subst(survivedParams, newClassTParams map (_.tpe))
@@ -1058,6 +1060,8 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
decl.setInfo(if (decl.isConstructor) tpe match {
case MethodType(args, resTpe) => MethodType(args, decl.owner.tpe)
} else tpe)
+ // log((decl, decl.tpe.bounds.hi))
+ // decl
}
/** Type transformation. It is applied to all symbols, compiled or loaded.
@@ -1515,7 +1519,12 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
if (settings.debug.value) log("now typing: " + meth + " in " + symbol.owner.fullName)
val d = new Duplicator
try {
- d.retyped(localTyper.context1.asInstanceOf[d.Context],
+ // log("duplicating tree: " + tree + "; " + symbol.owner)
+ // log("source: " + source + "; owner: " + source.owner)
+ // log("source encl class: " + source.enclClass)
+ // log("symbol encl class: " + symbol.enclClass)
+ // log(meth)
+ d.retyped(localTyper.context1.asInstanceOf[d.Context],
meth,
source.enclClass,
symbol.enclClass,
diff --git a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
index ba827f1421..cb03c61b50 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
@@ -170,6 +170,17 @@ abstract class Duplicators extends Analyzer {
typed(ddef)
}
+ private def inspectTpe(tpe: Type) = {
+ tpe match {
+ case MethodType(_, res) =>
+ res + ", " + res.bounds.hi + ", " + (res.bounds.hi match {
+ case TypeRef(_, _, args) if (args.length > 0) => args(0) + ", " + args(0).bounds.hi
+ case _ => "non-tref: " + res.bounds.hi.getClass
+ })
+ case _ =>
+ }
+ }
+
/** Special typer method for re-type checking trees. It expects a typed tree.
* Returns a typed tree that has fresh symbols for all definitions in the original tree.
*
@@ -224,11 +235,13 @@ abstract class Duplicators extends Analyzer {
super.typed(vdef, mode, pt)
case ldef @ LabelDef(name, params, rhs) =>
+ // log("label def: " + ldef)
ldef.tpe = null
val params1 = params map { p => Ident(updateSym(p.symbol)) }
super.typed(treeCopy.LabelDef(tree, name, params1, rhs), mode, pt)
case Bind(name, _) =>
+ // log("bind: " + tree)
invalidate(tree)
tree.tpe = null
super.typed(tree, mode, pt)
@@ -240,21 +253,29 @@ abstract class Duplicators extends Analyzer {
super.typed(tree, mode, pt)
case Select(th @ This(_), sel) if (oldClassOwner ne null) && (th.symbol == oldClassOwner) =>
- log("selection on this, no type ascription required")
+ // log("selection on this, no type ascription required")
// we use the symbol name instead of the tree name because the symbol may have been
// name mangled, rendering the tree name obsolete
- super.typed(atPos(tree.pos)(Select(This(newClassOwner), tree.symbol.name)), mode, pt)
+ // log(tree)
+ val t = super.typed(atPos(tree.pos)(Select(This(newClassOwner), tree.symbol.name)), mode, pt)
+ // log("typed to: " + t + "; tpe = " + t.tpe + "; " + inspectTpe(t.tpe))
+ t
case This(_) if (oldClassOwner ne null) && (tree.symbol == oldClassOwner) =>
// val tree1 = Typed(This(newClassOwner), TypeTree(fixType(tree.tpe.widen)))
+ // log("selection on this: " + tree)
val tree1 = This(newClassOwner)
+ // log("tree1: " + tree1)
if (settings.debug.value) log("mapped " + tree + " to " + tree1)
super.typed(atPos(tree.pos)(tree1), mode, pt)
case This(_) =>
+ // log("selection on this, plain: " + tree)
tree.symbol = updateSym(tree.symbol)
tree.tpe = null
- super.typed(tree, mode, pt)
+ val tree1 = super.typed(tree, mode, pt)
+ // log("plain this typed to: " + tree1)
+ tree1
case Super(qual, mix) if (oldClassOwner ne null) && (tree.symbol == oldClassOwner) =>
val tree1 = Super(qual, mix)
@@ -281,6 +302,7 @@ abstract class Duplicators extends Analyzer {
tree
case _ =>
+ // log("default: " + tree)
if (tree.hasSymbol && tree.symbol != NoSymbol && (tree.symbol.owner == definitions.AnyClass)) {
tree.symbol = NoSymbol // maybe we can find a more specific member in a subclass of Any (see AnyVal members, like ==)
}