From 98cf4014a3a14dbc348a464584133d90719bdbb8 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 22 Feb 2012 20:34:25 -0800 Subject: One last nudge for elidable. A method with return type Nothing elides into a call to ??? . It's the role ??? was born for. --- .../scala/reflect/internal/Definitions.scala | 1 + src/compiler/scala/reflect/internal/StdNames.scala | 2 ++ src/compiler/scala/reflect/internal/TreeGen.scala | 5 +++- .../scala/tools/nsc/transform/UnCurry.scala | 2 +- test/files/neg/elide-to-nothing.check | 4 --- test/files/neg/elide-to-nothing.flags | 1 - test/files/neg/elide-to-nothing.scala | 31 ---------------------- 7 files changed, 8 insertions(+), 38 deletions(-) delete mode 100644 test/files/neg/elide-to-nothing.check delete mode 100644 test/files/neg/elide-to-nothing.flags delete mode 100644 test/files/neg/elide-to-nothing.scala diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index d043230e48..ce5bb3d1c4 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -274,6 +274,7 @@ trait Definitions extends reflect.api.StandardDefinitions { def Predef_identity = getMember(PredefModule, nme.identity) def Predef_conforms = getMember(PredefModule, nme.conforms) def Predef_wrapRefArray = getMember(PredefModule, nme.wrapRefArray) + def Predef_??? = getMember(PredefModule, nme.???) /** Is `sym` a member of Predef with the given name? * Note: DON't replace this by sym == Predef_conforms/etc, as Predef_conforms is a `def` diff --git a/src/compiler/scala/reflect/internal/StdNames.scala b/src/compiler/scala/reflect/internal/StdNames.scala index f61fe7a457..a78e0cc939 100644 --- a/src/compiler/scala/reflect/internal/StdNames.scala +++ b/src/compiler/scala/reflect/internal/StdNames.scala @@ -260,6 +260,8 @@ trait StdNames extends NameManglers { self: SymbolTable => case _ => newTermName("x$" + i) } + val ??? = encode("???") + val wrapRefArray: NameType = "wrapRefArray" val wrapByteArray: NameType = "wrapByteArray" val wrapShortArray: NameType = "wrapShortArray" diff --git a/src/compiler/scala/reflect/internal/TreeGen.scala b/src/compiler/scala/reflect/internal/TreeGen.scala index cc882ad5ed..8c2a067d4d 100644 --- a/src/compiler/scala/reflect/internal/TreeGen.scala +++ b/src/compiler/scala/reflect/internal/TreeGen.scala @@ -250,7 +250,10 @@ abstract class TreeGen { * var x: T = _ * which is appropriate to the given Type. */ - def mkZero(tp: Type): Tree = Literal(mkConstantZero(tp)) setType tp + def mkZero(tp: Type): Tree = tp.typeSymbol match { + case NothingClass => mkMethodCall(Predef_???, Nil) setType NothingClass.tpe + case _ => Literal(mkConstantZero(tp)) setType tp + } def mkConstantZero(tp: Type): Constant = tp.typeSymbol match { case UnitClass => Constant(()) diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index 69bf006036..6a7fcc98c3 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -508,7 +508,7 @@ abstract class UnCurry extends InfoTransform // TODO - settings.noassertions.value temporarily retained to avoid // breakage until a reasonable interface is settled upon. if ((sym ne null) && (sym.elisionLevel.exists (_ < settings.elidebelow.value || settings.noassertions.value))) - super.transform(replaceElidableTree(tree)) + replaceElidableTree(tree) else tree match { case dd @ DefDef(mods, name, tparams, vparamss, tpt, rhs) => if (dd.symbol hasAnnotation VarargsClass) saveRepeatedParams(dd) diff --git a/test/files/neg/elide-to-nothing.check b/test/files/neg/elide-to-nothing.check deleted file mode 100644 index 3ef05aac9a..0000000000 --- a/test/files/neg/elide-to-nothing.check +++ /dev/null @@ -1,4 +0,0 @@ -elide-to-nothing.scala:14: error: Cannot elide where Nothing is required. - val b: Nothing = unimplemented() - ^ -one error found diff --git a/test/files/neg/elide-to-nothing.flags b/test/files/neg/elide-to-nothing.flags deleted file mode 100644 index 59a512e547..0000000000 --- a/test/files/neg/elide-to-nothing.flags +++ /dev/null @@ -1 +0,0 @@ --Xelide-below 500 diff --git a/test/files/neg/elide-to-nothing.scala b/test/files/neg/elide-to-nothing.scala deleted file mode 100644 index 5008e8bc1d..0000000000 --- a/test/files/neg/elide-to-nothing.scala +++ /dev/null @@ -1,31 +0,0 @@ - -/** Test which should fail compilation */ -class ElysianFailed { - - import ElysianField._ - - // fine - val a: Int = myInt - - // fine - unimplemented() - - // not fine - val b: Nothing = unimplemented() - -} - -object ElysianField { - - import annotation.elidable - - @elidable(100) def unimplemented(): Nothing = throw new UnsupportedOperationException - - @elidable(100) def myInt: Int = 17 - -} - - - - - -- cgit v1.2.3