diff options
author | Paul Phillips <paulp@improving.org> | 2013-09-18 07:25:59 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-09-18 07:25:59 -0700 |
commit | a8543ef28f8fc0152208f4eef763344657bf9e5a (patch) | |
tree | c82662e321ec6c291edbd51e30ff93bc6d93ce92 | |
parent | d45a3c8cc8e9f1d95d797d548a85abd8597f5bc7 (diff) | |
parent | 0f67e8dddcb8b087560fed90339d9235179dd1ea (diff) | |
download | scala-a8543ef28f8fc0152208f4eef763344657bf9e5a.tar.gz scala-a8543ef28f8fc0152208f4eef763344657bf9e5a.tar.bz2 scala-a8543ef28f8fc0152208f4eef763344657bf9e5a.zip |
Merge pull request #2955 from retronym/ticket/7853
SI-7853 Regression in explicit outer
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala | 9 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 2 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Trees.scala | 10 | ||||
-rw-r--r-- | test/files/pos/t4970b.scala | 32 | ||||
-rw-r--r-- | test/files/pos/t7853-partial-function.scala | 7 | ||||
-rw-r--r-- | test/files/pos/t7853.scala | 11 | ||||
-rw-r--r-- | test/files/run/compiler-asSeenFrom.check | 4 |
7 files changed, 64 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index a2bf5bf9e5..540b8f6c6c 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -90,7 +90,7 @@ abstract class ExplicitOuter extends InfoTransform sym expandName clazz sym.referenced = clazz - sym setInfo MethodType(Nil, restpe.widen) + sym setInfo MethodType(Nil, restpe) } def newOuterField(clazz: Symbol) = { val accFlags = SYNTHETIC | ARTIFACT | PARAMACCESSOR | ( if (clazz.isEffectivelyFinal) PrivateLocal else PROTECTED ) @@ -361,10 +361,9 @@ abstract class ExplicitOuter extends InfoTransform /** The definition tree of the outer accessor of current class */ def outerAccessorDef: Tree = localTyper typed { - outerAccessor(currentClass) match { - case acc if acc.isDeferred => DefDef(acc, EmptyTree) - case acc => DefDef(acc, Select(This(currentClass), outerField(currentClass))) - } + val acc = outerAccessor(currentClass) + val rhs = if (acc.isDeferred) EmptyTree else Select(This(currentClass), outerField(currentClass)) + DefDef(acc, rhs) } /** The definition tree of the outer accessor for class mixinClass. diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 3ac0b398ee..55268b1e1a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2606,7 +2606,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper } val rhs = methodBodyTyper.virtualizedMatch(match_, mode, B1.tpe) - val defdef = newDefDef(methodSym, rhs)(vparamss = mapParamss(methodSym)(newParam)) + val defdef = newDefDef(methodSym, rhs)(vparamss = mapParamss(methodSym)(newParam), tpt = TypeTree(B1.tpe)) (defdef, matchResTp) } diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index 38f1f0f725..2163a26b84 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -589,7 +589,11 @@ trait Trees extends api.Trees { self: SymbolTable => object TypeTree extends TypeTreeExtractor def TypeTree(tp: Type): TypeTree = TypeTree() setType tp - def TypeTree(sym: Symbol): TypeTree = atPos(sym.pos.focus)(TypeTree(sym.tpe_*.finalResultType)) + private def TypeTreeMemberType(sym: Symbol): TypeTree = { + // Needed for pos/t4970*.scala. See SI-7853 + val resType = (sym.owner.thisType memberType sym).finalResultType + atPos(sym.pos.focus)(TypeTree(resType)) + } def TypeBoundsTree(bounds: TypeBounds): TypeBoundsTree = TypeBoundsTree(TypeTree(bounds.lo), TypeTree(bounds.hi)) def TypeBoundsTree(sym: Symbol): TypeBoundsTree = atPos(sym.pos)(TypeBoundsTree(sym.info.bounds)) @@ -1039,7 +1043,7 @@ trait Trees extends api.Trees { self: SymbolTable => def newValDef(sym: Symbol, rhs: Tree)( mods: Modifiers = Modifiers(sym.flags), name: TermName = sym.name.toTermName, - tpt: Tree = TypeTree(sym) + tpt: Tree = TypeTreeMemberType(sym) ): ValDef = ( atPos(sym.pos)(ValDef(mods, name, tpt, rhs)) setSymbol sym ) @@ -1049,7 +1053,7 @@ trait Trees extends api.Trees { self: SymbolTable => name: TermName = sym.name.toTermName, tparams: List[TypeDef] = sym.typeParams map TypeDef, vparamss: List[List[ValDef]] = mapParamss(sym)(ValDef), - tpt: Tree = TypeTree(sym) + tpt: Tree = TypeTreeMemberType(sym) ): DefDef = ( atPos(sym.pos)(DefDef(mods, name, tparams, vparamss, tpt, rhs)) setSymbol sym ) diff --git a/test/files/pos/t4970b.scala b/test/files/pos/t4970b.scala new file mode 100644 index 0000000000..cf9a6a6ae9 --- /dev/null +++ b/test/files/pos/t4970b.scala @@ -0,0 +1,32 @@ +object Traits { + trait OuterClass[V <: OuterClass[V]#InnerClass] { + trait InnerClass {self: V => + def method = () + } + } + + trait SubOuterClass[T <: SubOuterClass[T]#SubInnerClass] extends OuterClass[T] { + trait SubInnerClass extends super.InnerClass {self: T => } + } + + trait SubOuterClass2[T <: SubOuterClass2[T]#SubInnerClass2] extends OuterClass[T] { + trait SubInnerClass2 extends super.InnerClass {self: InnerClass with T => } + } + +} + +// object Classes { +// class OuterClass[V <: OuterClass[V]#InnerClass] { +// class InnerClass {self: V => +// def method = () +// } +// } + +// class SubOuterClass[T <: SubOuterClass[T]#SubInnerClass] extends OuterClass[T] { +// class SubInnerClass extends super.InnerClass {self: T => } +// } + +// class SubOuterClass2[T <: SubOuterClass2[T]#SubInnerClass2] extends OuterClass[T] { +// class SubInnerClass2 extends super.InnerClass {self: InnerClass with T => } +// } +// } diff --git a/test/files/pos/t7853-partial-function.scala b/test/files/pos/t7853-partial-function.scala new file mode 100644 index 0000000000..b09254e99a --- /dev/null +++ b/test/files/pos/t7853-partial-function.scala @@ -0,0 +1,7 @@ +object Test { + + def testCons: Unit = { + def x[A](a: PartialFunction[Any, A]): A = a(0) + val eval0 = x { case list: List[Int @unchecked] => list } + } +} diff --git a/test/files/pos/t7853.scala b/test/files/pos/t7853.scala new file mode 100644 index 0000000000..b0e9221e22 --- /dev/null +++ b/test/files/pos/t7853.scala @@ -0,0 +1,11 @@ +trait S { + trait T { + this: Any => + + trait U { + trait V { + S.this + } + } + } +} diff --git a/test/files/run/compiler-asSeenFrom.check b/test/files/run/compiler-asSeenFrom.check index a1826c2784..7305504115 100644 --- a/test/files/run/compiler-asSeenFrom.check +++ b/test/files/run/compiler-asSeenFrom.check @@ -363,8 +363,8 @@ value jZ { // after parser value jZ { // after explicitouter protected val $outer: D.this.type - val $outer(): ll.D[T3] - val $outer(): ll.C[T1] + val $outer(): D.this.type + val $outer(): C.this.type def thisI(): I.this.type def thisC(): C.this.type def t2(): T2 |