diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/matching/CodeFactory.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala | 22 | ||||
-rw-r--r-- | src/library/scala/Option.scala | 2 |
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 |