diff options
author | Martin Odersky <odersky@gmail.com> | 2015-05-05 22:18:46 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-05-05 22:38:50 +0200 |
commit | dcb25c73739f1b5d40e92cd07acae5f7940f82a6 (patch) | |
tree | 38d2404791b55fc5cf35d12db444f0a9d2afcc60 /tests/pos/extractors.scala | |
parent | 7129cbe60c062be49aef8c27da461a11416e189c (diff) | |
download | dotty-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 'tests/pos/extractors.scala')
-rw-r--r-- | tests/pos/extractors.scala | 32 |
1 files changed, 32 insertions, 0 deletions
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) => ??? + } + } +} |