Skip to content

Commit fffb012

Browse files
Merge pull request #9614 from dotty-staging/fix-9603
Fix #9603: handle HK pattern bound type symbols
2 parents 1df0b15 + 20d4c24 commit fffb012

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,16 +466,25 @@ class SpaceEngine(using Context) extends SpaceLogic {
466466

467467
tp match {
468468
case tp @ AppliedType(tycon, args) =>
469-
if (tycon.isRef(defn.ArrayClass)) tp.derivedAppliedType(tycon, args.map(arg => erase(arg, inArray = true)))
470-
else tp.derivedAppliedType(tycon, args.map(arg => erase(arg, inArray = false)))
469+
if tycon.typeSymbol.isPatternBound then return WildcardType
470+
471+
val args2 =
472+
if (tycon.isRef(defn.ArrayClass)) args.map(arg => erase(arg, inArray = true))
473+
else args.map(arg => erase(arg, inArray = false))
474+
tp.derivedAppliedType(erase(tycon, inArray), args2)
475+
471476
case OrType(tp1, tp2) =>
472477
OrType(erase(tp1, inArray), erase(tp2, inArray))
478+
473479
case AndType(tp1, tp2) =>
474480
AndType(erase(tp1, inArray), erase(tp2, inArray))
481+
475482
case tp @ RefinedType(parent, _, _) =>
476483
erase(parent)
484+
477485
case tref: TypeRef if tref.typeSymbol.isPatternBound =>
478486
if (inArray) tref.underlying else WildcardType
487+
479488
case _ => tp
480489
}
481490
}
@@ -526,7 +535,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
526535
val mt: MethodType = unapp.widen match {
527536
case mt: MethodType => mt
528537
case pt: PolyType =>
529-
inContext(ctx.fresh.setNewTyperState()) {
538+
inContext(ctx.fresh.setExploreTyperState()) {
530539
val tvars = pt.paramInfos.map(newTypeVar)
531540
val mt = pt.instantiate(tvars).asInstanceOf[MethodType]
532541
scrutineeTp <:< mt.paramInfos(0)

tests/patmat/i9603.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
sealed abstract class Resource[+F[_], +A] {
2+
import Resource.{Allocate, Bind, Suspend}
3+
4+
def loop[G[x] >: F[x], B](current: Resource[G, Any]): G[B] =
5+
current match {
6+
case Allocate(r) => ???
7+
case Bind(s, fs) => ???
8+
case Suspend(r) => ???
9+
}
10+
}
11+
12+
object Resource {
13+
14+
final case class Allocate[F[_], A](resource: F[A])
15+
extends Resource[F, A]
16+
17+
final case class Bind[F[_], S, +A](source: Resource[F, S], fs: S => Resource[F, A])
18+
extends Resource[F, A]
19+
20+
final case class Suspend[F[_], A](resource: F[Resource[F, A]]) extends Resource[F, A]
21+
22+
}

0 commit comments

Comments
 (0)