Skip to content

Commit 1ea177d

Browse files
authored
Merge pull request #15254 from dwijnand/exh/ProjectionState
Extract unapply types like typedUnApply
2 parents b61036b + 83978df commit 1ea177d

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
556556
// Case unapplySeq:
557557
// 1. return the type `List[T]` where `T` is the element type of the unapplySeq return type `Seq[T]`
558558

559-
val resTp = mt.instantiate(scrutineeTp :: Nil).finalResultType
559+
val resTp = ctx.typeAssigner.safeSubstMethodParams(mt, scrutineeTp :: Nil).finalResultType
560560

561561
val sig =
562562
if (resTp.isRef(defn.BooleanClass))

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,15 @@ trait TypeAssigner {
279279
tp
280280
}
281281

282+
def safeSubstMethodParams(mt: MethodType, argTypes: List[Type])(using Context): Type =
283+
if mt.isResultDependent then safeSubstParams(mt.resultType, mt.paramRefs, argTypes)
284+
else mt.resultType
285+
282286
def assignType(tree: untpd.Apply, fn: Tree, args: List[Tree])(using Context): Apply = {
283287
val ownType = fn.tpe.widen match {
284288
case fntpe: MethodType =>
285289
if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping)
286-
if (fntpe.isResultDependent) safeSubstParams(fntpe.resultType, fntpe.paramRefs, args.tpes)
287-
else fntpe.resultType
290+
safeSubstMethodParams(fntpe, args.tpes)
288291
else
289292
errorType(i"wrong number of arguments at ${ctx.phase.prev} for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.srcPos)
290293
case t =>

tests/pos/i15226.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// scalac: -Werror
2+
class Proj { type State = String }
3+
4+
sealed trait ProjState:
5+
val a: Proj
6+
val b: a.State
7+
8+
object ProjState:
9+
def unapply(pj: ProjState): Some[(pj.a.type, pj.b.type)] = Some((pj.a, pj.b))
10+
11+
def test(pj: ProjState) = pj match
12+
case ProjState(p, s) =>

0 commit comments

Comments
 (0)