From e9bd1a35e7a70c96f8ee6a4535182ade766e6fa8 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 25 Apr 2007 13:13:15 +0000 Subject: fixed test case. --- src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 19 ++++++++++++------- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index bc8f39908c..c061b0c9fd 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -864,6 +864,12 @@ trait Parsers { /** XXX: Hook for IDE */ def expr(location: int): Tree = { + def isWildcard(t: Tree): boolean = t match { + case Ident(name1) if !implicitParams.isEmpty && name1 == implicitParams.head.name => true + case Typed(t1, _) => isWildcard(t1) + case Annotated(t1, _) => isWildcard(t1) + case _ => false + } var savedImplicitParams = implicitParams implicitParams = List() var res = in.token match { @@ -969,6 +975,11 @@ trait Parsers { } else if (annots.isEmpty || isTypeIntro) { t = atPos(pos) { val tpt = if (location != Local) compoundType(false) else typ() + if (isWildcard(t)) + (implicitParams: @unchecked) match { + case (vd @ ValDef(mods, name, _, _)) :: rest => + implicitParams = copy.ValDef(vd, mods, name, tpt.duplicate, EmptyTree) :: rest + } // this does not correspond to syntax, but is necessary to // accept closures. We might restrict closures to be between {...} only! Typed(t, (tpt /: annots) (makeAnnotated)) @@ -991,12 +1002,6 @@ trait Parsers { } stripParens(t) } - def isWildcard(t: Tree): boolean = t match { - case Ident(name1) if name1 == implicitParams.head.name => true - case Typed(t1, _) => isWildcard(t1) - case Annotated(t1, _) => isWildcard(t1) - case _ => false - } if (!implicitParams.isEmpty) if (isWildcard(res)) savedImplicitParams = savedImplicitParams ::: implicitParams else res = Function(implicitParams.reverse, res) @@ -1155,7 +1160,7 @@ trait Parsers { */ def blockExpr(): Tree = { val res = atPos(accept(LBRACE)) { - if (in.token == CASE) makeVisitor(caseClauses(), true) + if (in.token == CASE) Match(EmptyTree, caseClauses()) else block() } accept(RBRACE) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 86ce75eca6..ae53628530 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -603,7 +603,7 @@ trait Typers requires Analyzer { } else if (context.implicitsEnabled) { errorTree(tree, "missing arguments for "+meth+meth.locationString+ (if (meth.isConstructor) "" - else ";\nprefix this method with `&' if you want to treat it as a partially applied function")) + else ";\nfollow this method with `_' if you want to treat it as a partially applied function")) } else { setError(tree) } @@ -2452,9 +2452,19 @@ trait Typers requires Analyzer { typedIf(cond, thenp, elsep) case Match(selector, cases) => - val selector1 = checkDead(typed(selector)) - val cases1 = typedCases(tree, cases, selector1.tpe.widen, pt) - copy.Match(tree, selector1, cases1) setType ptOrLub(cases1 map (.tpe)) + if (selector == EmptyTree) { + val arity = if (isFunctionType(pt)) pt.normalize.typeArgs.length - 1 else 1 + val params = for (i <- List.range(0, arity)) yield + ValDef(Modifiers(PARAM | SYNTHETIC), unit.fresh.newName("x$"), TypeTree(), EmptyTree) + val ids = for (p <- params) yield Ident(p.name) + val selector1 = atPos(tree.pos) { if (arity == 1) ids.head else gen.mkTuple(ids) } + val body = copy.Match(tree, selector1, cases) + typed1(atPos(tree.pos) { Function(params, body) }, mode, pt) + } else { + val selector1 = checkDead(typed(selector)) + val cases1 = typedCases(tree, cases, selector1.tpe.widen, pt) + copy.Match(tree, selector1, cases1) setType ptOrLub(cases1 map (.tpe)) + } case Return(expr) => typedReturn(expr) -- cgit v1.2.3