Skip to content

Commit 6eeb06f

Browse files
oderskysmarter
authored andcommitted
Fix #2009: Fix placeholder params logic for lambdas (#2019)
* Fix #2009: Fix placeholder params logic for lambdas Logic was missing placeholders in rhs of lambdas. * Add comment * Fix typo
1 parent 8a826ee commit 6eeb06f

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -993,20 +993,22 @@ object Parsers {
993993
else {
994994
val saved = placeholderParams
995995
placeholderParams = Nil
996+
997+
def wrapPlaceholders(t: Tree) = try
998+
if (placeholderParams.isEmpty) t
999+
else new WildcardFunction(placeholderParams.reverse, t)
1000+
finally placeholderParams = saved
1001+
9961002
val t = expr1(location)
9971003
if (in.token == ARROW) {
998-
placeholderParams = saved
999-
closureRest(start, location, convertToParams(t))
1004+
placeholderParams = Nil // don't interpret `_' to the left of `=>` as placeholder
1005+
wrapPlaceholders(closureRest(start, location, convertToParams(t)))
10001006
}
10011007
else if (isWildcard(t)) {
10021008
placeholderParams = placeholderParams ::: saved
10031009
t
10041010
}
1005-
else
1006-
try
1007-
if (placeholderParams.isEmpty) t
1008-
else new WildcardFunction(placeholderParams.reverse, t)
1009-
finally placeholderParams = saved
1011+
else wrapPlaceholders(t)
10101012
}
10111013
}
10121014

tests/pos/i2009.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
3+
trait Gen[T] {
4+
def map[U](f: T => U): Gen[U] = ???
5+
}
6+
7+
def f[T](implicit g: Gen[T]): Gen[() => T] =
8+
g map ( () => _ )
9+
}

0 commit comments

Comments
 (0)