diff options
author | Martin Odersky <odersky@gmail.com> | 2016-09-24 19:18:12 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-09-24 19:18:12 +0200 |
commit | 4825980b0329c884d5b2e4e5377afdd16cefa3ad (patch) | |
tree | f770de4c25c9082d310124da387aad0bc8163543 /src/dotty/tools | |
parent | 962377ebc23a4c6a2757bee99e6558dd6a93c067 (diff) | |
download | dotty-4825980b0329c884d5b2e4e5377afdd16cefa3ad.tar.gz dotty-4825980b0329c884d5b2e4e5377afdd16cefa3ad.tar.bz2 dotty-4825980b0329c884d5b2e4e5377afdd16cefa3ad.zip |
Specially mark functions coming from wildcard expressions
That way, we can check functions for the ordering requirement as well.
We only have to remember that the last parameter of a wildcard function
does not precede its body (because the parameter is in fact part of the body).
Diffstat (limited to 'src/dotty/tools')
-rw-r--r-- | src/dotty/tools/dotc/ast/Positioned.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ast/untpd.scala | 7 | ||||
-rw-r--r-- | src/dotty/tools/dotc/parsing/Parsers.scala | 2 |
3 files changed, 13 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/ast/Positioned.scala b/src/dotty/tools/dotc/ast/Positioned.scala index 216446e93..8d364d439 100644 --- a/src/dotty/tools/dotc/ast/Positioned.scala +++ b/src/dotty/tools/dotc/ast/Positioned.scala @@ -171,7 +171,9 @@ abstract class Positioned extends DotClass with Product { } if (nonOverlapping) { this match { - case _: Function => // ignore, functions produced from wildcards (e.g. (_ op _) mix parameters and body + case _: WildcardFunction + if lastPositioned.isInstanceOf[ValDef] && !p.isInstanceOf[ValDef] => + // ignore transition from last wildcard parameter to body case _ => assert(!lastPos.exists || !p.pos.exists || lastPos.end <= p.pos.start, s"""position error, child positions overlap or in wrong order @@ -180,9 +182,9 @@ abstract class Positioned extends DotClass with Product { |1st child position = $lastPos |2nd child = $p |2nd child position = ${p.pos}""".stripMargin) - lastPositioned = p - lastPos = p.pos } + lastPositioned = p + lastPos = p.pos } p.checkPos(nonOverlapping) case xs: List[_] => diff --git a/src/dotty/tools/dotc/ast/untpd.scala b/src/dotty/tools/dotc/ast/untpd.scala index 7e1892253..092cb95c0 100644 --- a/src/dotty/tools/dotc/ast/untpd.scala +++ b/src/dotty/tools/dotc/ast/untpd.scala @@ -46,6 +46,13 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { override def isTerm = body.isTerm override def isType = body.isType } + /** A function created from a wildcard expression + * @param placeHolderParams a list of definitions of synthetic parameters + * @param body the function body where wildcards are replaced by + * references to synthetic parameters. + */ + class WildcardFunction(placeholderParams: List[ValDef], body: Tree) extends Function(placeholderParams, body) + case class InfixOp(left: Tree, op: Name, right: Tree) extends OpTree case class PostfixOp(od: Tree, op: Name) extends OpTree case class PrefixOp(op: Name, od: Tree) extends OpTree diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala index 6ba576a34..21eab6501 100644 --- a/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/src/dotty/tools/dotc/parsing/Parsers.scala @@ -973,7 +973,7 @@ object Parsers { else try if (placeholderParams.isEmpty) t - else Function(placeholderParams.reverse, t) + else new WildcardFunction(placeholderParams.reverse, t) finally placeholderParams = saved } |