Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dotty.tools
package dotc
package core

import Types._, Contexts._, Symbols._, Decorators._
import Types._, Contexts._, Symbols._, Decorators._, TypeApplications._
import util.SimpleIdentityMap
import collection.mutable
import printing.Printer
Expand Down Expand Up @@ -360,13 +360,15 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
* Q <: tp implies Q <: P and isUpper = true, or
* tp <: Q implies P <: Q and isUpper = false
*/
private def dependentParams(tp: Type, isUpper: Boolean): List[TypeParamRef] = tp match
private def dependentParams(tp: Type, isUpper: Boolean)(using Context): List[TypeParamRef] = tp match
case param: TypeParamRef if contains(param) =>
param :: (if (isUpper) upper(param) else lower(param))
case tp: AndType if isUpper =>
dependentParams(tp.tp1, isUpper) | (dependentParams(tp.tp2, isUpper))
case tp: OrType if !isUpper =>
dependentParams(tp.tp1, isUpper).intersect(dependentParams(tp.tp2, isUpper))
case EtaExpansion(tycon) =>
dependentParams(tycon, isUpper)
case _ =>
Nil

Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ object TypeApplications {
tycon.EtaExpand(tycon.typeParamSymbols)
}

def unapply(tp: Type)(using Context): Option[TypeRef] = tp match {
case tp @ HKTypeLambda(tparams, AppliedType(fn: TypeRef, args)) if (args == tparams.map(_.paramRef)) => Some(fn)
def unapply(tp: Type)(using Context): Option[Type] = tp match {
case tp @ HKTypeLambda(tparams, AppliedType(fn: Type, args))
if args.lazyZip(tparams).forall((arg, tparam) => arg == tparam.paramRef) => Some(fn)
case _ => None
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
if (tparams1.nonEmpty)
return recur(tp1.EtaExpand(tparams1), tp2) || fourthTry
tp2 match {
case EtaExpansion(tycon2) if tycon2.symbol.isClass && tycon2.symbol.is(JavaDefined) =>
case EtaExpansion(tycon2: TypeRef) if tycon2.symbol.isClass && tycon2.symbol.is(JavaDefined) =>
recur(tp1, tycon2) || fourthTry
case _ =>
fourthTry
Expand Down Expand Up @@ -769,7 +769,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
isNewSubType(tp1.parent)
case tp1: HKTypeLambda =>
def compareHKLambda = tp1 match {
case EtaExpansion(tycon1) if tycon1.symbol.isClass && tycon1.symbol.is(JavaDefined) =>
case EtaExpansion(tycon1: TypeRef) if tycon1.symbol.isClass && tycon1.symbol.is(JavaDefined) =>
// It's a raw type that was mistakenly eta-expanded to a hk-type.
// This can happen because we do not cook types coming from Java sources
recur(tycon1, tp2)
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i9676.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
trait SubtypeOf[A[_], B[_]]

object Test1 {
def instance[F[_], G[a] >: F[a]]: SubtypeOf[F, G] = new SubtypeOf[F, G] {}

val x: SubtypeOf[List, Seq] = instance
}

object Test2 {
def instance[G[_], F[a] <: G[a]]: SubtypeOf[F, G] = new SubtypeOf[F, G] {}

val x: SubtypeOf[List, Seq] = instance
}