summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorAntonio Cunei <antonio.cunei@epfl.ch>2009-11-09 16:13:33 +0000
committerAntonio Cunei <antonio.cunei@epfl.ch>2009-11-09 16:13:33 +0000
commite981bccdb7874726af0896efdadb5e192d25c14a (patch)
tree68ec4c2c9764a935c7efd72cf00a7206b6e18166 /src/compiler
parentdf502f4ffa5ebf83e7e97a270504202e00f512ec (diff)
downloadscala-e981bccdb7874726af0896efdadb5e192d25c14a.tar.gz
scala-e981bccdb7874726af0896efdadb5e192d25c14a.tar.bz2
scala-e981bccdb7874726af0896efdadb5e192d25c14a.zip
Adds isDefinedAt to Function1. As a consequence,
code that mixes in PartialFunction now have to define isDefinedAt as override. Fixes #2225.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index eec523a2b8..36ca4f399d 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -282,7 +282,7 @@ abstract class UnCurry extends InfoTransform with TypingTransformers {
* class $anon() extends Object() with PartialFunction[T, R] with ScalaObject {
* def apply(x: T): R = (x: @unchecked) match {
* { case P_i if G_i => E_i }_i=1..n
- * def isDefinedAt(x: T): boolean = (x: @unchecked) match {
+ * override def isDefinedAt(x: T): boolean = (x: @unchecked) match {
* case P_1 if G_1 => true
* ...
* case P_n if G_n => true
@@ -291,9 +291,12 @@ abstract class UnCurry extends InfoTransform with TypingTransformers {
* }
* new $anon()
*
- * However, if one of the patterns P_i if G_i is a default pattern, generate instead
+ * However, if one of the patterns P_i if G_i is a default pattern, it should generate instead
*
- * def isDefinedAt(x: T): boolean = true
+ * override def isDefinedAt(x: T): boolean = true
+ *
+ * which is the default in Function1 (and PartialFunction) anyway, so
+ * no overridden def is emitted.
*/
def transformFunction(fun: Function): Tree = {
val fun1 = deEta(fun)
@@ -335,7 +338,7 @@ abstract class UnCurry extends InfoTransform with TypingTransformers {
}
val members = {
if (fun.tpe.typeSymbol == PartialFunctionClass) {
- val isDefinedAtMethod = anonClass.newMethod(fun.pos, nme.isDefinedAt).setFlag(FINAL)
+ val isDefinedAtMethod = anonClass.newMethod(fun.pos, nme.isDefinedAt).setFlag(FINAL | OVERRIDE)
isDefinedAtMethod.setInfo(MethodType(isDefinedAtMethod.newSyntheticValueParams(formals),
BooleanClass.tpe))
anonClass.info.decls enter isDefinedAtMethod
@@ -353,8 +356,12 @@ abstract class UnCurry extends InfoTransform with TypingTransformers {
(cases map transformCase) :::
List(CaseDef(Ident(nme.WILDCARD), EmptyTree, Literal(false))))
}
- List(applyMethodDef(mkUnchecked(fun.body)),
- DefDef(isDefinedAtMethod, mkUnchecked(idbody(isDefinedAtMethod.paramss.head.head))))
+ val isDef=idbody(isDefinedAtMethod.paramss.head.head)
+ if (isDef == Literal(true))
+ List(applyMethodDef(mkUnchecked(fun.body)))
+ else
+ List(applyMethodDef(mkUnchecked(fun.body)),
+ DefDef(isDefinedAtMethod, mkUnchecked(isDef)))
} else {
List(applyMethodDef(fun.body))
}