Skip to content

Commit 9da99f1

Browse files
committed
Parentheses around a wildcard should not produce a lambda
`(_)` and `(_: T)` should not be converted to functions x => x (x: T) => x
1 parent 08e8802 commit 9da99f1

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ object Parsers {
322322
case Ident(name1) => placeholderParams.nonEmpty && name1 == placeholderParams.head.name
323323
case Typed(t1, _) => isWildcard(t1)
324324
case Annotated(t1, _) => isWildcard(t1)
325+
case Parens(t1) => isWildcard(t1)
325326
case _ => false
326327
}
327328

tests/pos/i903.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
object Test {
2+
def contains(s: String, i: Int) = true
3+
def test1 = {
4+
val f = contains("", (_: Int))
5+
val ff = contains("", ((_: Int)))
6+
f.apply(0)
7+
// sandbox/eta.scala:4: error: type mismatch:
8+
// found : Int => Int
9+
// required: Int
10+
// val f = contains("", (_: Int))
11+
// ^
12+
// sandbox/eta.scala:5: error: apply is not a member of Boolean(f)
13+
// f.apply(0)
14+
// ^
15+
}
16+
17+
def test2 = {
18+
val f = "".contains("", (_: Int)) // dotc:
19+
f.apply(0)
20+
// sandbox/eta.scala:18: error: apply is not a member of Boolean(f)
21+
// f.apply(0)
22+
// ^
23+
}
24+
}

0 commit comments

Comments
 (0)