aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Applications.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-05-05 22:18:46 +0200
committerMartin Odersky <odersky@gmail.com>2015-05-05 22:38:50 +0200
commitdcb25c73739f1b5d40e92cd07acae5f7940f82a6 (patch)
tree38d2404791b55fc5cf35d12db444f0a9d2afcc60 /src/dotty/tools/dotc/typer/Applications.scala
parent7129cbe60c062be49aef8c27da461a11416e189c (diff)
downloaddotty-dcb25c73739f1b5d40e92cd07acae5f7940f82a6.tar.gz
dotty-dcb25c73739f1b5d40e92cd07acae5f7940f82a6.tar.bz2
dotty-dcb25c73739f1b5d40e92cd07acae5f7940f82a6.zip
Drop the requirement that extractors with `get` must implement Product
We used to require that the result type of an extractor `get` is a product, or else the type of the `get` itself would be taken as the result type of the unapply. This is now relaxed so that we automatically select with _1, _2, ... as soon as there are multiple argument patterns, and (1) the result type is not a Seq, (2) the number of consecutive product conselectors matches the number of arguments.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Applications.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 7a826fee8..ce181c0cc 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] = {
@@ -747,6 +750,7 @@ trait Applications extends Compatibility { self: Typer =>
case _ => args
}
if (argTypes.length != bunchedArgs.length) {
+ println(argTypes)
ctx.error(d"wrong number of argument patterns for $qual; expected: ($argTypes%, %)", tree.pos)
argTypes = argTypes.take(args.length) ++
List.fill(argTypes.length - args.length)(WildcardType)