diff options
-rw-r--r-- | src/dotty/tools/dotc/typer/Applications.scala | 9 | ||||
-rw-r--r-- | tests/pos/extractors.scala | 32 |
2 files changed, 38 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 7a826fee8..fec6482b8 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -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] = { diff --git a/tests/pos/extractors.scala b/tests/pos/extractors.scala new file mode 100644 index 000000000..8e5b0e9d2 --- /dev/null +++ b/tests/pos/extractors.scala @@ -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) => ??? + } + } +} |