summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2009-06-16 11:17:07 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2009-06-16 11:17:07 +0000
commit73746f649a39156df26a289022b2f6127f8145a7 (patch)
tree2ee55ec04397dfcabb118dab7a04791cf4a2bae6 /src/compiler
parent53ed9b920e738e784289548d7cc90e8e2dcd0124 (diff)
downloadscala-73746f649a39156df26a289022b2f6127f8145a7.tar.gz
scala-73746f649a39156df26a289022b2f6127f8145a7.tar.bz2
scala-73746f649a39156df26a289022b2f6127f8145a7.zip
cleaned up eta-expansion of partial named appli...
cleaned up eta-expansion of partial named applications
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala10
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala38
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) {