From 73746f649a39156df26a289022b2f6127f8145a7 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Tue, 16 Jun 2009 11:17:07 +0000 Subject: cleaned up eta-expansion of partial named appli... cleaned up eta-expansion of partial named applications --- .../scala/tools/nsc/typechecker/EtaExpansion.scala | 10 ++++++ .../scala/tools/nsc/typechecker/Typers.scala | 38 ++++++---------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala index 68f486a600..deae3f114f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala +++ b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala @@ -79,6 +79,16 @@ trait EtaExpansion { self: Analyzer => Ident(vname) setPos tree.pos } tree match { + // a partial application using named arguments has the following form: + // { val qual$1 = qual + // val x$1 = arg1 + // [...] + // val x$n = argn + // qual$1.fun(x$1, ..)..(.., x$n) } + // Eta-expansion has to be performed on `fun' + case Block(stats, fun) => + defs ++= stats + liftoutPrefix(fun) case Apply(fn, args) => treeCopy.Apply(tree, liftoutPrefix(fn), List.mapConserve(args)(liftout)) setType null case TypeApply(fn, args) => diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 2bd8ae2041..1a2495f00c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -780,39 +780,21 @@ trait Typers { self: Analyzer => case mt: MethodType if (((mode & (EXPRmode | FUNmode | LHSmode)) == EXPRmode) && (context.undetparams.isEmpty || (mode & POLYmode) != 0)) => - // if (isNamedApplyBlock(tree)), we know that `tree' is a transformed - // named application and has the following form: - // { val x$1 = arg1 - // [...] - // val x$n = argn - // fun(x$1, ..)..(.., x$n) } - // Eta-Expansion needs to be performed on the method `fun', not on - // the entire block, so we extract the fun (`tree1') apply eta-expansion, - // and re-construct the block at the end: - // { val x$1 = arg1 - // [...] - // val x$n = argn - // (y$1, .., y$n) => fun(x$1, ..)..(.., x$n)(y$1, ..)..(.., y$n) } - val (tree1, meth, isExpanded) = tree match { - case Block(_, tree1) if isNamedApplyBlock(tree) => - context.namedApplyBlockInfo = None - (tree1, tree1.symbol, true) - case _ => (tree, tree.symbol, false) + + val meth = tree match { + // a partial named application is a block (see comment in EtaExpansion) + case Block(_, tree1) => tree1.symbol + case _ => tree.symbol } if (!meth.isConstructor && //isCompatible(tparamsToWildcards(mt, context.undetparams), pt) && isFunctionType(pt))/* && (pt <:< functionType(mt.paramTypes map (t => WildcardType), WildcardType)))*/ { // (4.2) - if (settings.debug.value) log("eta-expanding "+tree1+":"+tree1.tpe+" to "+pt) - checkParamsConvertible(tree1.pos, tree1.tpe) - val tree2 = etaExpand(context.unit, tree1) - //println("eta "+tree1+" ---> "+tree2+":"+tree2.tpe) - val typedFun = typed(tree2, mode, pt) - tree match { - case Block(stats, fun) if (isExpanded) => - treeCopy.Block(tree, stats, typedFun).setType(typedFun.tpe) - case _ => typedFun - } + if (settings.debug.value) log("eta-expanding "+tree+":"+tree.tpe+" to "+pt) + checkParamsConvertible(tree.pos, tree.tpe) + val tree1 = etaExpand(context.unit, tree) + //println("eta "+tree+" ---> "+tree1+":"+tree1.tpe) + typed(tree1, mode, pt) } else if (!meth.isConstructor && mt.paramTypes.isEmpty) { // (4.3) adapt(typed(Apply(tree, List()) setPos tree.pos), mode, pt) } else if (context.implicitsEnabled) { -- cgit v1.2.3