From 9da99f11035d94afba05f4bb768b3a9766b26faf Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 2 Nov 2015 11:45:28 +0100 Subject: [PATCH 1/2] Parentheses around a wildcard should not produce a lambda `(_)` and `(_: T)` should not be converted to functions x => x (x: T) => x --- src/dotty/tools/dotc/parsing/Parsers.scala | 1 + tests/pos/i903.scala | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/pos/i903.scala diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala index 4b22eac953f5..caa15c7ff4a8 100644 --- a/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/src/dotty/tools/dotc/parsing/Parsers.scala @@ -322,6 +322,7 @@ object Parsers { case Ident(name1) => placeholderParams.nonEmpty && name1 == placeholderParams.head.name case Typed(t1, _) => isWildcard(t1) case Annotated(t1, _) => isWildcard(t1) + case Parens(t1) => isWildcard(t1) case _ => false } diff --git a/tests/pos/i903.scala b/tests/pos/i903.scala new file mode 100644 index 000000000000..c84cb16366c9 --- /dev/null +++ b/tests/pos/i903.scala @@ -0,0 +1,24 @@ +object Test { + def contains(s: String, i: Int) = true + def test1 = { + val f = contains("", (_: Int)) + val ff = contains("", ((_: Int))) + f.apply(0) + // sandbox/eta.scala:4: error: type mismatch: + // found : Int => Int + // required: Int + // val f = contains("", (_: Int)) + // ^ + // sandbox/eta.scala:5: error: apply is not a member of Boolean(f) + // f.apply(0) + // ^ + } + + def test2 = { + val f = "".contains("", (_: Int)) // dotc: + f.apply(0) + // sandbox/eta.scala:18: error: apply is not a member of Boolean(f) + // f.apply(0) + // ^ + } +} From 2bcc0b06cf6f2d83148206275ffe7b8617fdb776 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 2 Nov 2015 13:16:42 +0100 Subject: [PATCH 2/2] Add tests for wildcards without types As suggested by review. --- tests/pos/i903.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/pos/i903.scala b/tests/pos/i903.scala index c84cb16366c9..5afb6e53010c 100644 --- a/tests/pos/i903.scala +++ b/tests/pos/i903.scala @@ -3,6 +3,8 @@ object Test { def test1 = { val f = contains("", (_: Int)) val ff = contains("", ((_: Int))) + val g: Int => Boolean = contains("", (_)) + val gg: Int => Boolean = contains("", ((_))) f.apply(0) // sandbox/eta.scala:4: error: type mismatch: // found : Int => Int