Skip to content

Commit bd81a2f

Browse files
committed
Fix #5574
Re-typing the pattern in GADT context is unnecessary - reducing the pattern will on its own perform the same subtyping checks. Previously if a pattern binding a HK type was inlined, a warning saying that its kind is different from the kind of its parameter was emitted _after_ preparing for reduction. This replaced the type of the Bind node with an error, preventing the bind from being located and narrowed when reducing the inline match.
1 parent ab10e7b commit bd81a2f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
855855
}
856856
if (!isImplicit) caseBindingsBuf += scrutineeBinding
857857
val gadtCtx = typer.gadtContext(gadtSyms).addMode(Mode.GADTflexible)
858-
val pat1 = typer.typedPattern(cdef.pat, scrutType)(gadtCtx)
859858
val fromBuf = mutable.ListBuffer.empty[TypeSymbol]
860859
val toBuf = mutable.ListBuffer.empty[TypeSymbol]
861-
if (reducePattern(caseBindingsBuf, fromBuf, toBuf, scrutineeSym.termRef, pat1)(gadtCtx) && guardOK) {
860+
if (reducePattern(caseBindingsBuf, fromBuf, toBuf, scrutineeSym.termRef, cdef.pat)(gadtCtx) && guardOK) {
862861
val caseBindings = caseBindingsBuf.toList
863862
val from = fromBuf.toList
864863
val to = toBuf.toList

tests/pos/i5574.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.typelevel._
2+
3+
object i5574 {
4+
class Box[F[_]]
5+
6+
inline def foo[T] <: Any =
7+
inline erasedValue[T] match {
8+
case _: Box[f] =>
9+
type t = f
10+
23
11+
}
12+
13+
foo[Box[List]]
14+
}

0 commit comments

Comments
 (0)