Skip to content

Commit 4825980

Browse files
committed
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).
1 parent 962377e commit 4825980

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ abstract class Positioned extends DotClass with Product {
171171
}
172172
if (nonOverlapping) {
173173
this match {
174-
case _: Function => // ignore, functions produced from wildcards (e.g. (_ op _) mix parameters and body
174+
case _: WildcardFunction
175+
if lastPositioned.isInstanceOf[ValDef] && !p.isInstanceOf[ValDef] =>
176+
// ignore transition from last wildcard parameter to body
175177
case _ =>
176178
assert(!lastPos.exists || !p.pos.exists || lastPos.end <= p.pos.start,
177179
s"""position error, child positions overlap or in wrong order
@@ -180,9 +182,9 @@ abstract class Positioned extends DotClass with Product {
180182
|1st child position = $lastPos
181183
|2nd child = $p
182184
|2nd child position = ${p.pos}""".stripMargin)
183-
lastPositioned = p
184-
lastPos = p.pos
185185
}
186+
lastPositioned = p
187+
lastPos = p.pos
186188
}
187189
p.checkPos(nonOverlapping)
188190
case xs: List[_] =>

src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
4646
override def isTerm = body.isTerm
4747
override def isType = body.isType
4848
}
49+
/** A function created from a wildcard expression
50+
* @param placeHolderParams a list of definitions of synthetic parameters
51+
* @param body the function body where wildcards are replaced by
52+
* references to synthetic parameters.
53+
*/
54+
class WildcardFunction(placeholderParams: List[ValDef], body: Tree) extends Function(placeholderParams, body)
55+
4956
case class InfixOp(left: Tree, op: Name, right: Tree) extends OpTree
5057
case class PostfixOp(od: Tree, op: Name) extends OpTree
5158
case class PrefixOp(op: Name, od: Tree) extends OpTree

src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ object Parsers {
973973
else
974974
try
975975
if (placeholderParams.isEmpty) t
976-
else Function(placeholderParams.reverse, t)
976+
else new WildcardFunction(placeholderParams.reverse, t)
977977
finally placeholderParams = saved
978978
}
979979

0 commit comments

Comments
 (0)