Skip to content

Commit e47afef

Browse files
committed
adapt specification for unrelated types
1 parent 2f8dc49 commit e47afef

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

compiler/src/dotty/tools/dotc/transform/IsInstanceOfChecker.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package transform
44
import util.Positions._
55
import MegaPhase.MiniPhase
66
import core._
7-
import Contexts.Context, Types._, Decorators._, Symbols._, typer._
7+
import Contexts.Context, Types._, Decorators._, Symbols._, typer._, ast._
88
import TypeUtils._, Flags._
99
import config.Printers.{ transforms => debug }
1010

@@ -51,8 +51,8 @@ object Checkable {
5151
* 4. if `P = Array[T]`, checkable(E, T) where `E` is the element type of `X`, defaults to `Any`.
5252
* 5. if `P` is `pre.F[Ts]` and `pre.F` refers to a class which is not `Array`:
5353
* (a) replace `Ts` with fresh type variables `Xs`
54-
* (b) instantiate `Xs` with the constraint `pre.F[Xs] <:< X`
55-
* (c) `pre.F[Xs] <:< P`
54+
* (b) `pre.F[Xs] <:< X` with `Xs` instantiated as `Es`
55+
* (c) `pre.F[Es] <:< P`
5656
* 6. if `P = T1 | T2` or `P = T1 & T2`, checkable(X, T1) && checkable(X, T2).
5757
* 7. if `P` is a refinement type, FALSE
5858
* 8. otherwise, TRUE
@@ -72,13 +72,14 @@ object Checkable {
7272

7373
def isClassDetermined(X: Type, P: AppliedType)(implicit ctx: Context) = {
7474
val AppliedType(tycon, _) = P
75-
val tvars = tycon.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
75+
val typeLambda = tycon.ensureHK.asInstanceOf[TypeLambda]
76+
val tvars = constrained(typeLambda, untpd.EmptyTree, alwaysAddTypeVars = true)._2.map(_.tpe)
7677
val P1 = tycon.appliedTo(tvars)
7778

7879
debug.println("P1 : " + P1.show)
7980
debug.println("X : " + X.show)
8081

81-
!(P1 <:< X) || {
82+
(P1 <:< X) && {
8283
val res = isFullyDefined(P1, ForceDegree.noBottom) && P1 <:< P
8384
debug.println("P1 <:< P = " + res)
8485
res
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait C[T]
2+
class D[T]
3+
4+
class Test {
5+
def foo[T](x: C[T]) = x match {
6+
case _: D[T] => // error
7+
}
8+
}

0 commit comments

Comments
 (0)