Skip to content

Commit

Permalink
Merge pull request #15254 from dwijnand/exh/ProjectionState
Browse files Browse the repository at this point in the history
Extract unapply types like typedUnApply
  • Loading branch information
odersky authored May 26, 2022
2 parents b61036b + 83978df commit 1ea177d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
// Case unapplySeq:
// 1. return the type `List[T]` where `T` is the element type of the unapplySeq return type `Seq[T]`

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

val sig =
if (resTp.isRef(defn.BooleanClass))
Expand Down
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,15 @@ trait TypeAssigner {
tp
}

def safeSubstMethodParams(mt: MethodType, argTypes: List[Type])(using Context): Type =
if mt.isResultDependent then safeSubstParams(mt.resultType, mt.paramRefs, argTypes)
else mt.resultType

def assignType(tree: untpd.Apply, fn: Tree, args: List[Tree])(using Context): Apply = {
val ownType = fn.tpe.widen match {
case fntpe: MethodType =>
if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping)
if (fntpe.isResultDependent) safeSubstParams(fntpe.resultType, fntpe.paramRefs, args.tpes)
else fntpe.resultType
safeSubstMethodParams(fntpe, args.tpes)
else
errorType(i"wrong number of arguments at ${ctx.phase.prev} for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.srcPos)
case t =>
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/i15226.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// scalac: -Werror
class Proj { type State = String }

sealed trait ProjState:
val a: Proj
val b: a.State

object ProjState:
def unapply(pj: ProjState): Some[(pj.a.type, pj.b.type)] = Some((pj.a, pj.b))

def test(pj: ProjState) = pj match
case ProjState(p, s) =>

0 comments on commit 1ea177d

Please sign in to comment.