aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools')
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala12
-rw-r--r--src/dotty/tools/dotc/typer/TypeAssigner.scala5
2 files changed, 8 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index 0757c8187..8d7e9d164 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -525,14 +525,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
/** if `tp2 == p.type` and `p: q.type` then try `tp1 <:< q.type` as a last effort.*/
def comparePaths = tp2 match {
case tp2: TermRef =>
- tp2.info match {
- case tp2i: TermRef =>
- isSubType(tp1, tp2i)
- case ExprType(tp2i: TermRef) if (ctx.phase.id > ctx.gettersPhase.id) =>
- // After getters, val x: T becomes def x: T
- isSubType(tp1, tp2i)
- case _ =>
- false
+ tp2.info.widenExpr match {
+ case tp2i: SingletonType =>
+ isSubType(tp1, tp2i) // see z1720.scala for a case where this can arise even in typer.
+ case _ => false
}
case _ =>
false
diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala
index e0a9dbafc..a6e2deb23 100644
--- a/src/dotty/tools/dotc/typer/TypeAssigner.scala
+++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala
@@ -59,7 +59,10 @@ trait TypeAssigner {
case _ => false
}
def apply(tp: Type): Type = tp match {
- case tp: TermRef if toAvoid(tp) && variance > 0 =>
+ case tp: TermRef
+ if toAvoid(tp) && (variance > 0 || tp.info.widenExpr <:< tp) =>
+ // Can happen if `x: y.type`, then `x.type =:= y.type`, hence we can widen `x.type`
+ // to y.type in all contexts, not just covariant ones.
apply(tp.info.widenExpr)
case tp: TypeRef if toAvoid(tp) =>
tp.info match {