diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-12-02 13:26:01 +0100 |
---|---|---|
committer | Den Shabalin <den.shabalin@gmail.com> | 2013-12-10 16:02:44 +0100 |
commit | 4be6ea147a7d8f300c1e6db2a216b50fe8cf5dc7 (patch) | |
tree | 904e5b1ca930a5745d1f0e4a4734b4f421cfd263 /src/compiler | |
parent | f3c260bf89942ff58796ed7d242ad2e106331f83 (diff) | |
download | scala-4be6ea147a7d8f300c1e6db2a216b50fe8cf5dc7.tar.gz scala-4be6ea147a7d8f300c1e6db2a216b50fe8cf5dc7.tar.bz2 scala-4be6ea147a7d8f300c1e6db2a216b50fe8cf5dc7.zip |
Provide a way for unapply macro to obtain a list of subpattens
This commit introduces internal attachment that allows unapply macros to
be aware of their sub patterns and tweak their expansion depending
on that info.
At the moment this is not possible due to the way pattern macros are
expanded:
case MacroPat(inner1, inner2) => ...
During type checking this will expand as
MacroPat.unapply(<unapply-dummy>)
Meaning that macro can’t see inner1 and inner2 in it’s macroApplication.
To circumvent this we attach that info as an attachment to the dummy.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala b/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala index ba135d7d25..069d6d5fb2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala @@ -391,8 +391,10 @@ trait PatternTypers { else freshUnapplyArgType() ) ) + val unapplyArgTree = Ident(unapplyArg) updateAttachment SubpatternsAttachment(args) + // clearing the type is necessary so that ref will be stabilized; see bug 881 - val fun1 = typedPos(fun.pos)(Apply(Select(fun.clearType(), unapplyMethod), Ident(unapplyArg) :: Nil)) + val fun1 = typedPos(fun.pos)(Apply(Select(fun.clearType(), unapplyMethod), unapplyArgTree :: Nil)) def makeTypedUnApply() = { // the union of the expected type and the inferred type of the argument to unapply |