Skip to content

Commit 117102f

Browse files
committed
Fix #1447: Make X$ <:< X.type when X is an object
This allows objects to be easily aliased
1 parent 62348de commit 117102f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
165165
// However the original judgment should be true.
166166
case _ =>
167167
}
168-
val sym1 = tp1.symbol
168+
val sym1 =
169+
if (tp1.symbol.is(ModuleClass) && tp2.symbol.is(ModuleVal))
170+
// For convenience we want X$ <:< X.type
171+
// This is safe because X$ self-type is X.type
172+
tp1.symbol.companionModule
173+
else
174+
tp1.symbol
169175
if ((sym1 ne NoSymbol) && (sym1 eq tp2.symbol))
170176
ctx.erasedTypes ||
171177
sym1.isStaticOwner ||

tests/pos/i1447.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
case object X
2+
3+
object Test {
4+
val Alias = X
5+
6+
val x: X.type = Alias
7+
}

0 commit comments

Comments
 (0)