Skip to content

Commit 51ab200

Browse files
committed
Merge pull request #865 from dotty-staging/fix-module-alias-subtyping
Fix hole in subtyping of modules
2 parents 08df804 + 7947a7b commit 51ab200

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
197197
val cls1 = tp1.cls
198198
cls1.classInfo.selfType.derivesFrom(cls2) &&
199199
cls2.classInfo.selfType.derivesFrom(cls1)
200-
case tp1: TermRef if tp2.cls eq tp1.symbol.moduleClass =>
201-
isSubType(tp1.prefix, cls2.owner.thisType)
200+
case tp1: TermRef if cls2.is(Module) && cls2.eq(tp1.widen.typeSymbol) =>
201+
cls2.isStaticOwner ||
202+
isSubType(tp1.prefix, cls2.owner.thisType) ||
203+
secondTry(tp1, tp2)
202204
case _ =>
203205
secondTry(tp1, tp2)
204206
}
@@ -257,9 +259,12 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
257259
}
258260
comparePolyParam
259261
case tp1: ThisType =>
262+
val cls1 = tp1.cls
260263
tp2 match {
261-
case tp2: TermRef if tp1.cls eq tp2.symbol.moduleClass =>
262-
isSubType(tp1.cls.owner.thisType, tp2.prefix)
264+
case tp2: TermRef if cls1.is(Module) && cls1.eq(tp2.widen.typeSymbol) =>
265+
cls1.isStaticOwner ||
266+
isSubType(cls1.owner.thisType, tp2.prefix) ||
267+
thirdTry(tp1, tp2)
263268
case _ =>
264269
thirdTry(tp1, tp2)
265270
}

tests/pos/range.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.math._
2+
import collection.immutable.NumericRange
3+
object Test {
4+
val r1: scala.collection.immutable.Range.Partial = ???
5+
val r2: scala.Range.Partial = r1
6+
def until(d: BigDecimal, end: BigDecimal): Range.Partial[BigDecimal, NumericRange.Exclusive[BigDecimal]] =
7+
new Range.Partial(until(d, end, _))
8+
def until(d: BigDecimal, end: BigDecimal, step: BigDecimal) = Range.BigDecimal(d, end, step)
9+
}

0 commit comments

Comments
 (0)