From 79cbdefa47d77b6785b614b895dc03ede84a7328 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 17 Nov 2009 13:12:31 +0000 Subject: Allow implicit modifier on single-parameter fun... Allow implicit modifier on single-parameter function literals. Fixes and closes #1492. --- src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 10 +++++++++- test/files/pos/implicits.scala | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index a4f228cffb..356f4621a4 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -957,7 +957,7 @@ self => */ def statement(location: Int): Tree = expr(location) // !!! still needed? - /** Expr ::= (Bindings | Id | `_') `=>' Expr + /** Expr ::= (Bindings | [`implicit'] Id | `_') `=>' Expr * | Expr1 * ResultExpr ::= (Bindings | Id `:' CompoundType) `=>' Block * | Expr1 @@ -1057,6 +1057,14 @@ self => atPos(in.skipToken()) { Throw(expr()) } + case IMPLICIT => + val start = in.skipToken() + val param0 = convertToParam(atPos(in.offset)(Ident(ident()))) + val param = treeCopy.ValDef(param0, param0.mods | Flags.IMPLICIT, param0.name, param0.tpt, param0.rhs) + atPos(start, in.offset) { + accept(ARROW) + Function(List(param), if (location != InBlock) expr() else block()) + } case _ => var t = postfixExpr() if (in.token == EQUALS) { diff --git a/test/files/pos/implicits.scala b/test/files/pos/implicits.scala index aeb6591507..485d24101e 100644 --- a/test/files/pos/implicits.scala +++ b/test/files/pos/implicits.scala @@ -1,3 +1,17 @@ +// #1435 +object t1435 { + implicit def a(s:String):String = error("") + implicit def a(i:Int):String = error("") + implicit def b(i:Int):String = error("") +} + +class C1435 { + val v:String = { + import t1435.a + 2 + } +} + // #1579 object Test1579 { class Column -- cgit v1.2.3