Skip to content

Commit f19b6dd

Browse files
authored
Merge pull request #1458 from dotty-staging/fix-compare-singletons
Fixes for comparing and avoiding singletons
2 parents 5a5f9d7 + b8bb504 commit f19b6dd

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
525525
/** if `tp2 == p.type` and `p: q.type` then try `tp1 <:< q.type` as a last effort.*/
526526
def comparePaths = tp2 match {
527527
case tp2: TermRef =>
528-
tp2.info match {
529-
case tp2i: TermRef =>
530-
isSubType(tp1, tp2i)
531-
case ExprType(tp2i: TermRef) if (ctx.phase.id > ctx.gettersPhase.id) =>
532-
// After getters, val x: T becomes def x: T
533-
isSubType(tp1, tp2i)
534-
case _ =>
535-
false
528+
tp2.info.widenExpr match {
529+
case tp2i: SingletonType =>
530+
isSubType(tp1, tp2i) // see z1720.scala for a case where this can arise even in typer.
531+
case _ => false
536532
}
537533
case _ =>
538534
false

src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ trait TypeAssigner {
5959
case _ => false
6060
}
6161
def apply(tp: Type): Type = tp match {
62-
case tp: TermRef if toAvoid(tp) && variance > 0 =>
62+
case tp: TermRef
63+
if toAvoid(tp) && (variance > 0 || tp.info.widenExpr <:< tp) =>
64+
// Can happen if `x: y.type`, then `x.type =:= y.type`, hence we can widen `x.type`
65+
// to y.type in all contexts, not just covariant ones.
6366
apply(tp.info.widenExpr)
6467
case tp: TypeRef if toAvoid(tp) =>
6568
tp.info match {

test/dotc/tests.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ class tests extends CompilerTest {
111111

112112
@Test def pos_859 = compileFile(posSpecialDir, "i859", scala2mode)(allowDeepSubtypes)
113113

114+
@Test def pos_t5545 = {
115+
// compile by hand in two batches, since junit lacks the infrastructure to
116+
// compile files in multiple batches according to _1, _2, ... suffixes.
117+
compileFile(posSpecialDir, "spec-t5545/S_1")
118+
compileFile(posSpecialDir, "spec-t5545/S_2")
119+
}
120+
114121
@Test def new_all = compileFiles(newDir, twice)
115122
@Test def repl_all = replFiles(replDir)
116123

File renamed without changes.

0 commit comments

Comments
 (0)