diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala b/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala index 192483b4ce3c..74bfd0491a14 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala @@ -195,16 +195,16 @@ trait PatternTypers { def skolems = try skolemBuffer.toList finally skolemBuffer.clear() def apply(tp: Type): Type = mapOver(tp) match { - case tp @ TypeRef(NoPrefix, tpSym, Nil) if eligible(tpSym) => - val bounds = ( - if (variance.isInvariant) tpSym.tpeHK.bounds - else if (variance.isPositive) TypeBounds.upper(tpSym.tpeHK) - else TypeBounds.lower(tpSym.tpeHK) + case TypeRef(NoPrefix, tpSym, Nil) if eligible(tpSym) => + val bounds = genPolyType(tpSym.typeParams, + if (variance.isInvariant) tpSym.tpe.bounds + else if (variance.isPositive) TypeBounds.upper(tpSym.tpe) + else TypeBounds.lower(tpSym.tpe) ) // origin must be the type param so we can deskolemize val skolem = context.owner.newGADTSkolem(freshTypeName("?" + tpSym.name), tpSym, bounds) skolemBuffer += skolem - logResult(s"Created gadt skolem $skolem: ${skolem.tpe_*} to stand in for $tpSym")(skolem.tpe_*) + logResult(s"Created gadt skolem $skolem: ${skolem.tpeHK} to stand in for $tpSym")(skolem.tpeHK) case tp1 => tp1 } } diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index dc10202117c4..1cf542d9979b 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -2438,7 +2438,7 @@ trait Types // interpret symbol's info in terms of the type's prefix and type args - protected def relativeInfo: Type = appliedType(sym.info.asSeenFrom(pre, sym.owner), argsOrDummies) + protected def relativeInfo: Type = appliedType(sym.info.asSeenFrom(pre, sym.owner), args) // @M: propagate actual type params (args) to `tp`, by replacing // formal type parameters with actual ones. If tp is higher kinded, diff --git a/test/files/neg/hk-existential-lb.check b/test/files/neg/hk-existential-lb.check index 287da95c412f..4779aa9cc784 100644 --- a/test/files/neg/hk-existential-lb.check +++ b/test/files/neg/hk-existential-lb.check @@ -1,7 +1,7 @@ hk-existential-lb.scala:5: error: type mismatch; found : Functor[Option] required: Functor[_[x] >: List[x]] -Note: Option <: Any, but class Functor is invariant in type F. +Note: Option <: [x]Any, but class Functor is invariant in type F. You may wish to define F as +F instead. (SLS 4.5) val someF: Functor[F] forSome { type F[x] >: List[x] } = new Functor[Option] ^ diff --git a/test/files/pos/t12295.scala b/test/files/pos/t12295.scala new file mode 100644 index 000000000000..24150cb97103 --- /dev/null +++ b/test/files/pos/t12295.scala @@ -0,0 +1,33 @@ +object Test { + sealed trait Foo[+A] // sealed or not doesn't matter + case class ImplA[A](a: A) extends Foo[A] + case class ImplAny[A](a: Any) extends Foo[A] + + trait Bar[+G[_]] // must be covariant + + def err[F[_]](): Unit = { + val x: Foo[Foo[Bar[F]]] = ??? + + x match { + case ImplAny(ImplAny(_)) => ??? + case ImplAny(ImplA(_)) => ??? + case ImplA(_) => ??? + case ImplAny(_) => ??? + case _ => ??? + } + + x match { + case ImplA(ImplA(_)) => ??? + case ImplA(ImplAny(_)) => ??? + case ImplA(y) => y.toString + case ImplA(y) => y match { + case ImplA(_) => ??? + case _ => ??? + } + case ImplA(y) => y + case _ => ??? + } + + () + } +} diff --git a/test/files/run/repl-kind.check b/test/files/run/repl-kind.check index d18f1af0b3b2..099619c2fc21 100644 --- a/test/files/run/repl-kind.check +++ b/test/files/run/repl-kind.check @@ -14,8 +14,8 @@ Either's kind is F[+A1,+A2] This is a type constructor: a 1st-order-kinded type. scala> :k -v scala.collection.SortedMapOps -scala.collection.SortedMapOps's kind is X[K,+V,+CC[X,Y] <: scala.collection.Map[X,Y] with scala.collection.SortedMapOps[X, Y, CC, _],+C <: scala.collection.SortedMapOps[K,V,CC,C]] -* -> * -(+)-> (* -> * -> *(scala.collection.Map[X,Y] with scala.collection.SortedMapOps[X, Y, CC, _])) -(+)-> *(scala.collection.SortedMapOps[K,V,CC,C]) -(+)-> * +scala.collection.SortedMapOps's kind is X[K,+V,+CC[X,Y] <: [X, Y]scala.collection.Map[X,Y] with scala.collection.SortedMapOps[X, Y, CC, _],+C <: scala.collection.SortedMapOps[K,V,CC,C]] +* -> * -(+)-> (* -> * -> *([X, Y]scala.collection.Map[X,Y] with scala.collection.SortedMapOps[X, Y, CC, _])) -(+)-> *(scala.collection.SortedMapOps[K,V,CC,C]) -(+)-> * This is a type constructor that takes type constructor(s): a higher-kinded type. scala> :kind -v Tuple2