diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 9 | ||||
-rw-r--r-- | test/files/pos/bug460.scala | 9 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 235d4b6df5..f08b08b3d7 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1214,7 +1214,14 @@ trait Parsers extends NewScanners with MarkupParsers { case LPAREN | LBRACE if (canApply) => // again, position should be on idetifier, not ( var pos = if (t.pos == NoPosition) i2p(inCurrentPos) else t.pos - simpleExprRest(atPos(pos) { Apply(stripParens(t), argumentExprs()) }, true) + simpleExprRest(atPos(pos) { + // look for anonymous function application like (f _)(x) and translate to (f _).apply(x), bug #460 + val sel = t match { + case Parens(List(Typed(_, _: Function))) => Select(stripParens(t), nme.apply) + case _ => stripParens(t) + } + Apply(sel, argumentExprs()) + }, true) case USCORE => atPos(inSkipToken) { Typed(stripParens(t), Function(List(), EmptyTree)) } case _ => diff --git a/test/files/pos/bug460.scala b/test/files/pos/bug460.scala new file mode 100644 index 0000000000..7bf9374e91 --- /dev/null +++ b/test/files/pos/bug460.scala @@ -0,0 +1,9 @@ +object Bug460 { + def testFun(x : Int, y : Int) = x + y + val fn = testFun _ + + fn(1, 2) // Ok + (testFun(_, _))(1, 2) // Ok + (testFun _).apply(1, 2) + (testFun _)(1, 2) // Error! (but no longer) +}
\ No newline at end of file |