diff options
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 12 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/TypeAssigner.scala | 5 | ||||
-rw-r--r-- | test/dotc/tests.scala | 7 | ||||
-rw-r--r-- | tests/pos-special/spec-t5545/S_1.scala (renamed from tests/pending/pos/spec-t5545/S_1.scala) | 0 | ||||
-rw-r--r-- | tests/pos-special/spec-t5545/S_2.scala (renamed from tests/pending/pos/spec-t5545/S_2.scala) | 0 | ||||
-rw-r--r-- | tests/pos/z1720.scala (renamed from tests/pending/pos/z1720.scala) | 0 |
6 files changed, 15 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 { diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index ad4846c18..31e74fa97 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -111,6 +111,13 @@ class tests extends CompilerTest { @Test def pos_859 = compileFile(posSpecialDir, "i859", scala2mode)(allowDeepSubtypes) + @Test def pos_t5545 = { + // compile by hand in two batches, since junit lacks the infrastructure to + // compile files in multiple batches according to _1, _2, ... suffixes. + compileFile(posSpecialDir, "spec-t5545/S_1") + compileFile(posSpecialDir, "spec-t5545/S_2") + } + @Test def new_all = compileFiles(newDir, twice) @Test def repl_all = replFiles(replDir) diff --git a/tests/pending/pos/spec-t5545/S_1.scala b/tests/pos-special/spec-t5545/S_1.scala index 59ec1fd85..59ec1fd85 100644 --- a/tests/pending/pos/spec-t5545/S_1.scala +++ b/tests/pos-special/spec-t5545/S_1.scala diff --git a/tests/pending/pos/spec-t5545/S_2.scala b/tests/pos-special/spec-t5545/S_2.scala index 59ec1fd85..59ec1fd85 100644 --- a/tests/pending/pos/spec-t5545/S_2.scala +++ b/tests/pos-special/spec-t5545/S_2.scala diff --git a/tests/pending/pos/z1720.scala b/tests/pos/z1720.scala index 7394d428c..7394d428c 100644 --- a/tests/pending/pos/z1720.scala +++ b/tests/pos/z1720.scala |