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
15 changes: 12 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -466,16 +466,25 @@ class SpaceEngine(using Context) extends SpaceLogic {

tp match {
case tp @ AppliedType(tycon, args) =>
if (tycon.isRef(defn.ArrayClass)) tp.derivedAppliedType(tycon, args.map(arg => erase(arg, inArray = true)))
else tp.derivedAppliedType(tycon, args.map(arg => erase(arg, inArray = false)))
if tycon.typeSymbol.isPatternBound then return WildcardType

val args2 =
if (tycon.isRef(defn.ArrayClass)) args.map(arg => erase(arg, inArray = true))
else args.map(arg => erase(arg, inArray = false))
tp.derivedAppliedType(erase(tycon, inArray), args2)

case OrType(tp1, tp2) =>
OrType(erase(tp1, inArray), erase(tp2, inArray))

case AndType(tp1, tp2) =>
AndType(erase(tp1, inArray), erase(tp2, inArray))

case tp @ RefinedType(parent, _, _) =>
erase(parent)

case tref: TypeRef if tref.typeSymbol.isPatternBound =>
if (inArray) tref.underlying else WildcardType

case _ => tp
}
}
Expand Down Expand Up @@ -526,7 +535,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
val mt: MethodType = unapp.widen match {
case mt: MethodType => mt
case pt: PolyType =>
inContext(ctx.fresh.setNewTyperState()) {
inContext(ctx.fresh.setExploreTyperState()) {
val tvars = pt.paramInfos.map(newTypeVar)
val mt = pt.instantiate(tvars).asInstanceOf[MethodType]
scrutineeTp <:< mt.paramInfos(0)
Expand Down
22 changes: 22 additions & 0 deletions tests/patmat/i9603.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
sealed abstract class Resource[+F[_], +A] {
import Resource.{Allocate, Bind, Suspend}

def loop[G[x] >: F[x], B](current: Resource[G, Any]): G[B] =
current match {
case Allocate(r) => ???
case Bind(s, fs) => ???
case Suspend(r) => ???
}
}

object Resource {

final case class Allocate[F[_], A](resource: F[A])
extends Resource[F, A]

final case class Bind[F[_], S, +A](source: Resource[F, S], fs: S => Resource[F, A])
extends Resource[F, A]

final case class Suspend[F[_], A](resource: F[Resource[F, A]]) extends Resource[F, A]

}