Skip to content

Extract unapply types like typedUnApply #15254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) =>