Skip to content
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
9 changes: 6 additions & 3 deletions src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ object Applications {
sels.takeWhile(_.exists).toList
}

def getUnapplySelectors(tp: Type, args:List[untpd.Tree], pos: Position = NoPosition)(implicit ctx: Context): List[Type] =
if (defn.isProductSubType(tp) && args.length > 1) productSelectorTypes(tp, pos)
else tp :: Nil
def getUnapplySelectors(tp: Type, args: List[untpd.Tree], pos: Position = NoPosition)(implicit ctx: Context): List[Type] =
if (args.length > 1 && !(tp.derivesFrom(defn.SeqClass))) {
val sels = productSelectorTypes(tp, pos)
if (sels.length == args.length) sels
else tp :: Nil
} else tp :: Nil

def unapplyArgs(unapplyResult: Type, unapplyFn:Tree, args:List[untpd.Tree], pos: Position = NoPosition)(implicit ctx: Context): List[Type] = {

Expand Down
32 changes: 32 additions & 0 deletions tests/pos/extractors.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
object test {

class Tree
class Apply(val fun: Tree, val args: List[Tree]) extends Tree

trait DeconstructorCommon[T >: Null <: AnyRef] {
var field: T = null
def get: this.type = this
def isEmpty: Boolean = field eq null
def isDefined = !isEmpty
def unapply(s: T): this.type ={
field = s
this
}
}

trait ApplyDeconstructor extends DeconstructorCommon[Apply] {
def _1: Tree
def _2: List[Tree]
}

object Apply extends ApplyDeconstructor {
def _1: Tree = field.fun
def _2: List[Tree] = field.args
}

def assocsFromApply(tree: Tree) = {
tree match {
case Apply(fun, args) => ???
}
}
}