From 5b4e69b582c15246f392bc9e94cfd2293f033938 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Fri, 21 Aug 2020 14:27:38 +0200 Subject: [PATCH 1/2] Fix #9603: handle HK pattern bound type symbols --- .../dotty/tools/dotc/transform/patmat/Space.scala | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index c292a79b9cae..f157f9d69eb3 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -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 } } @@ -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) From 20d4c243288555cdd2677f4d5fd4b75c13880c42 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Fri, 21 Aug 2020 14:29:00 +0200 Subject: [PATCH 2/2] Add test --- tests/patmat/i9603.scala | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/patmat/i9603.scala diff --git a/tests/patmat/i9603.scala b/tests/patmat/i9603.scala new file mode 100644 index 000000000000..c7d2f7cd1d97 --- /dev/null +++ b/tests/patmat/i9603.scala @@ -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] + +}