From e3fa6df7cf2ead50efc6c35ca1ad877f506775da Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 22 Feb 2017 12:12:25 +0100 Subject: [PATCH 1/3] Fix #2009: Fix placeholder params logic for lambdas Logic was missing placeholders in rhs of lambdas. --- .../src/dotty/tools/dotc/parsing/Parsers.scala | 16 +++++++++------- tests/pos/i2009.scala | 9 +++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 tests/pos/i2009.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index b46bc401da68..f08de708bcd1 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -993,20 +993,22 @@ object Parsers { else { val saved = placeholderParams placeholderParams = Nil + + def wrapPlaceholders(t: Tree) = try + if (placeholderParams.isEmpty) t + else new WildcardFunction(placeholderParams.reverse, t) + finally placeholderParams = saved + val t = expr1(location) if (in.token == ARROW) { - placeholderParams = saved - closureRest(start, location, convertToParams(t)) + placeholderParams = Nil + wrapPlaceholders(closureRest(start, location, convertToParams(t))) } else if (isWildcard(t)) { placeholderParams = placeholderParams ::: saved t } - else - try - if (placeholderParams.isEmpty) t - else new WildcardFunction(placeholderParams.reverse, t) - finally placeholderParams = saved + else wrapPlaceholders(t) } } diff --git a/tests/pos/i2009.scala b/tests/pos/i2009.scala new file mode 100644 index 000000000000..e2cf472038d7 --- /dev/null +++ b/tests/pos/i2009.scala @@ -0,0 +1,9 @@ +object Test { + + trait Gen[T] { + def map[U](f: T => U): Gen[U] = ??? + } + + def f[T](implicit g: Gen[T]): Gen[() => T] = + g map ( () => _ ) +} From d403a5b7e05c01b0a2d9f54536ca588f9df658a6 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 22 Feb 2017 14:25:00 +0100 Subject: [PATCH 2/3] Add comment --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index f08de708bcd1..fa276439d7b9 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1001,7 +1001,7 @@ object Parsers { val t = expr1(location) if (in.token == ARROW) { - placeholderParams = Nil + placeholderParams = Nil // don't interprete `_' to the left of `=>` as a placeholder wrapPlaceholders(closureRest(start, location, convertToParams(t))) } else if (isWildcard(t)) { From 9193b1564ef081e2745c2e305a7f53d804f0f8a1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 22 Feb 2017 14:40:08 +0100 Subject: [PATCH 3/3] Fix typo --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index fa276439d7b9..c14108d2e5c9 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1001,7 +1001,7 @@ object Parsers { val t = expr1(location) if (in.token == ARROW) { - placeholderParams = Nil // don't interprete `_' to the left of `=>` as a placeholder + placeholderParams = Nil // don't interpret `_' to the left of `=>` as placeholder wrapPlaceholders(closureRest(start, location, convertToParams(t))) } else if (isWildcard(t)) {