summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2006-11-29 22:37:01 +0000
committerBurak Emir <emir@epfl.ch>2006-11-29 22:37:01 +0000
commitca3a272ce620c618684432646ca1614ddc3c0b3d (patch)
tree412330ca0e2ed07ff1772d8e80628f4b2252b147 /src
parent78db4cf7fe84fe2431fd8204a84d385e0fe8141d (diff)
downloadscala-ca3a272ce620c618684432646ca1614ddc3c0b3d.tar.gz
scala-ca3a272ce620c618684432646ca1614ddc3c0b3d.tar.bz2
scala-ca3a272ce620c618684432646ca1614ddc3c0b3d.zip
more functionality for -Xkilloption
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/matching/CodeFactory.scala6
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala22
-rw-r--r--src/library/scala/Option.scala2
3 files changed, 17 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
index 56278738b4..afae88ee56 100644
--- a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
+++ b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
@@ -223,5 +223,11 @@ trait CodeFactory requires transform.ExplicitOuter {
typed {
Apply(Select(tree, nme.ne), List(Literal(Constant(null))))
}
+
+ def IsNull(tree:Tree) =
+ typed {
+ Apply(Select(tree, nme.eq), List(Literal(Constant(null))))
+ }
+
}
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index 0538942fd0..f1fad915c0 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -353,30 +353,28 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter
if settings.Xkilloption.value && wasNone(nne.tpe) =>
atPos(tree.pos) { typer.typed { Literal(Constant(null)) }}
- case Apply(Select(t, nme.isEmpty),List()) // t.isEmpty -> t ne null
+ case Apply(Select(t, nme.isEmpty),List()) // t.isEmpty -> t eq null
if settings.Xkilloption.value && wasOption(t.tpe) =>
- NotNull(t)
+ IsNull(t)
case Apply(Select(t, nme.get),List()) // t.get -> t if T <: Option[AnyRef]
if settings.Xkilloption.value && wasOptionRef(t.tpe) =>
t
- case Select(t, n)
- if settings.Xkilloption.value && {Console.println(t.tpe); wasOption(t.tpe)} && n != nme.get =>
+ case Select(t, n) // methods ...
+ if settings.Xkilloption.value && wasOption(t.tpe) && n != nme.get =>
def ntpe = if(t.tpe.isInstanceOf[SingleType]) t.tpe.widen else t.tpe
val otpe = atPhase(phase.prev){ntpe}
val nt = atPos(tree.pos) { typer.typed {
- Select(If(NotNull(t),
- Apply(Select(New(TypeTree( definitions.someType(otpe.typeArgs(0)))), nme.CONSTRUCTOR), List(t)),
- gen.mkAttributedRef(definitions.NoneClass)),
- n)
+ If(NotNull(t),
+ Apply(Select(New(TypeTree( definitions.someType(otpe.typeArgs(0)))), nme.CONSTRUCTOR), List(t)),
+ gen.mkAttributedRef(definitions.NoneClass))
}}
- Console.println("nt == "+nt)
- nt
- case _ // e.g. this.blabla().x -> t
+ copy.Select(tree,nt,n)
+
+ case _ // e.g. map.get("bar") -> fix type
if settings.Xkilloption.value
&& wasOptionRef(tree.tpe) =>
- Console.println("cuckoo" + tree)
super.transform(tree.setType(atPhase(phase.prev){tree.tpe}.typeArgs(0)))
// </removeOption>
diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala
index cb92cbd39d..ee0e32e636 100644
--- a/src/library/scala/Option.scala
+++ b/src/library/scala/Option.scala
@@ -22,7 +22,7 @@ import Predef._
* @author Matthias Zenger
* @version 1.0, 16/07/2003
*/
-sealed abstract class Option[+A] extends Iterable[A] {
+sealed abstract class Option[+A] extends Iterable[A] with Product {
def isEmpty: Boolean = this match {
case None => true