diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2012-06-03 23:21:26 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-06-03 23:23:15 +0200 |
commit | 82d2f0c80d5e45df7599a8d4c7d980772d3d4222 (patch) | |
tree | a418fc772b37368452c3d98d803d1327eb97deed | |
parent | 85cd96da352c929ea0ce4ba236730579e09c5c4b (diff) | |
download | scala-82d2f0c80d5e45df7599a8d4c7d980772d3d4222.tar.gz scala-82d2f0c80d5e45df7599a8d4c7d980772d3d4222.tar.bz2 scala-82d2f0c80d5e45df7599a8d4c7d980772d3d4222.zip |
SI-5313 Revert to two traversals in substThisAndSym.
Partially reverts 334872e.
-rw-r--r-- | src/compiler/scala/reflect/internal/Types.scala | 21 | ||||
-rw-r--r-- | test/files/pos/t5313.scala | 30 |
2 files changed, 40 insertions, 11 deletions
diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 67c858356c..c3d473187e 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -749,12 +749,18 @@ trait Types extends api.Types { self: SymbolTable => def substThis(from: Symbol, to: Symbol): Type = substThis(from, to.thisType) - /** Performs both substThis and substSym in one traversal. + /** Performs both substThis and substSym, in that order. + * + * [JZ] Reverted `SubstThisAndSymMap` from 334872, which was not the same as + * `substThis(from, to).substSym(symsFrom, symsTo)`. + * + * `SubstThisAndSymMap` performs a breadth-first map over this type, which meant that + * symbol substitution occured before `ThisType` substitution. Consequently, in substitution + * of a `SingleType(ThisType(`from`), sym), symbols were rebound to `from` rather than `to`. */ - def substThisAndSym(from: Symbol, to: Type, symsFrom: List[Symbol], symsTo: List[Symbol]): Type = { + def substThisAndSym(from: Symbol, to: Type, symsFrom: List[Symbol], symsTo: List[Symbol]): Type = if (symsFrom eq symsTo) substThis(from, to) - else new SubstThisAndSymMap(from, to, symsFrom, symsTo) apply this - } + else substThis(from, to).substSym(symsFrom, symsTo) /** Returns all parts of this type which satisfy predicate `p` */ def filter(p: Type => Boolean): List[Type] = new FilterTypeCollector(p) collect this @@ -4518,13 +4524,6 @@ trait Types extends api.Types { self: SymbolTable => case _ => mapOver(tp) } } - class SubstThisAndSymMap(fromThis: Symbol, toThis: Type, fromSyms: List[Symbol], toSyms: List[Symbol]) - extends SubstSymMap(fromSyms, toSyms) { - override def apply(tp: Type): Type = tp match { - case ThisType(sym) if sym == fromThis => apply(toThis) - case _ => super.apply(tp) - } - } class SubstWildcardMap(from: List[Symbol]) extends TypeMap { def apply(tp: Type): Type = try { diff --git a/test/files/pos/t5313.scala b/test/files/pos/t5313.scala new file mode 100644 index 0000000000..e77b73ca4c --- /dev/null +++ b/test/files/pos/t5313.scala @@ -0,0 +1,30 @@ +object DepBug { + class A { + class B + def mkB = new B + def m(b : B) = b + } + + trait Dep { + val a : A + val b : a.B + } + + val dep = new Dep { + val a = new A + val b = a.mkB + } + + def useDep(d : Dep) { + import d._ + a.m(b) // OK + } + + { + import dep._ + a.m(b) // OK with 2.9.1.final, error on trunk + } + + dep.a.m(dep.b) + +} |