From b02c80c2c240b58e8030d2ccf7dc7d7a36b3afe9 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 15 Nov 2015 19:17:40 +0100 Subject: [PATCH 1/5] Fix #938 - escaping reference. Need to avoid also symbols in ThisTypes --- src/dotty/tools/dotc/typer/TypeAssigner.scala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala index af5fdd428b23..f7cda1ef6d4f 100644 --- a/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -46,10 +46,9 @@ trait TypeAssigner { // TODO: measure the cost of using `existsPart`, and if necessary replace it // by a `TypeAccumulator` where we have set `stopAtStatic = true`. tp existsPart { - case tp: NamedType => - forbidden contains tp.symbol - case _ => - false + case tp: NamedType => forbidden contains tp.symbol + case tp: ThisType => forbidden contains tp.cls + case _ => false } def apply(tp: Type): Type = tp match { case tp: TermRef if toAvoid(tp) && variance > 0 => From bd76fbaec088de73deeb443681071bd311624dc1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 16 Nov 2015 09:25:13 +0100 Subject: [PATCH 2/5] Fix bug in phase identification for Ycheck -Ycheck:era checked after phase resolveSuper. This was due to an overly simplistic containsPhase check. --- src/dotty/tools/dotc/core/Phases.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala index 8d5ec08f70af..970a9297ac2e 100644 --- a/src/dotty/tools/dotc/core/Phases.scala +++ b/src/dotty/tools/dotc/core/Phases.scala @@ -7,6 +7,7 @@ import dotty.tools.backend.jvm.{LabelDefs, GenBCode} import util.DotClass import DenotTransformers._ import Denotations._ +import Decorators._ import config.Printers._ import scala.collection.mutable.{ListBuffer, ArrayBuffer} import dotty.tools.dotc.transform.TreeTransforms.{TreeTransformer, MiniPhase, TreeTransform} @@ -121,10 +122,9 @@ object Phases { phase } squashedPhases += phaseToAdd - val shouldAddYCheck = YCheckAfter.exists(nm => phaseToAdd.phaseName.contains(nm)) || YCheckAll + val shouldAddYCheck = YCheckAfter.containsPhase(phaseToAdd) || YCheckAll if (shouldAddYCheck) { val checker = new TreeChecker - squashedPhases += checker } } From 7c6870e4d5ac3a9206aed16633c5f0a92fc97b5d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 16 Nov 2015 09:54:10 +0100 Subject: [PATCH 3/5] Compensate for getter transform in isSubType test Getters transform `T` to `=> T`. This means that `=> T <: T` might need to be true after getters. Observed in the wild tree checking t938.scala after getters. --- src/dotty/tools/dotc/core/TypeComparer.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 2045de3cedd3..66965f427801 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -488,6 +488,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { case _ => tp2 isRef ObjectClass } compareJavaArray + case tp1: ExprType if ctx.phase.id >= ctx.gettersPhase.id => + // getters might have converted T to => T, need to compensate. + isSubType(tp1.widenExpr, tp2) case _ => false } From 0a15bb5be1d7a6e8ee635ef3a5eea4e6094ebce0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 16 Nov 2015 10:17:34 +0100 Subject: [PATCH 4/5] Add test case --- test/dotc/scala-collections.whitelist | 2 +- tests/pos/i938.scala | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i938.scala diff --git a/test/dotc/scala-collections.whitelist b/test/dotc/scala-collections.whitelist index c5cd38f4db34..1c3931c6a9d4 100644 --- a/test/dotc/scala-collections.whitelist +++ b/test/dotc/scala-collections.whitelist @@ -186,7 +186,7 @@ ./scala-scala/src/library/scala/collection/SortedSetLike.scala ./scala-scala/src/library/scala/collection/Traversable.scala -# https://github.com/lampepfl/dotty/issues/938 +# https://github.com/lampepfl/dotty/issues/938 (but relies also on #937 being fixed) #./scala-scala/src/library/scala/collection/TraversableLike.scala ./scala-scala/src/library/scala/collection/TraversableProxy.scala diff --git a/tests/pos/i938.scala b/tests/pos/i938.scala new file mode 100644 index 000000000000..cf8fd76e36bb --- /dev/null +++ b/tests/pos/i938.scala @@ -0,0 +1,21 @@ +object Test { + import scala.collection._ + + trait T { + def f() : Unit + } + + def view = new T { + def f() = () + } + + trait TLike[+A, RR] { self => + + def repr: RR = ??? + + def view2 = new TraversableView[A, RR] { + protected lazy val underlying = self.repr + override def foreach[U](f: A => U): Unit = ??? + } + } +} From 3ec504cf4586dc99964b1b049eae745077c20b37 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 16 Nov 2015 15:57:25 +0100 Subject: [PATCH 5/5] Fix comparison --- src/dotty/tools/dotc/core/TypeComparer.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 66965f427801..6e2346710b62 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -488,7 +488,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { case _ => tp2 isRef ObjectClass } compareJavaArray - case tp1: ExprType if ctx.phase.id >= ctx.gettersPhase.id => + case tp1: ExprType if ctx.phase.id > ctx.gettersPhase.id => // getters might have converted T to => T, need to compensate. isSubType(tp1.widenExpr, tp2) case _ =>