diff options
author | Paul Phillips <paulp@improving.org> | 2011-01-18 18:54:27 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-01-18 18:54:27 +0000 |
commit | 8c713da3d02131bb3931c152a6bda9785e1f464e (patch) | |
tree | 9f9372144f22356be4dc2ab41d93218485203f68 /src/library | |
parent | 98de3e5bad0e670fbe2e0ea6d511dc57b282f332 (diff) | |
download | scala-8c713da3d02131bb3931c152a6bda9785e1f464e.tar.gz scala-8c713da3d02131bb3931c152a6bda9785e1f464e.tar.bz2 scala-8c713da3d02131bb3931c152a6bda9785e1f464e.zip |
What is, I think, the only possible solution to...
What is, I think, the only possible solution to bug #4158 given the
current ways of controlling implicits. Let's just be glad there's one
instead of zero. Closes #4158, review by moors.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/LowPriorityImplicits.scala | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/library/scala/LowPriorityImplicits.scala b/src/library/scala/LowPriorityImplicits.scala index 6fce638061..61cd60cb52 100644 --- a/src/library/scala/LowPriorityImplicits.scala +++ b/src/library/scala/LowPriorityImplicits.scala @@ -36,6 +36,24 @@ class LowPriorityImplicits { implicit def doubleWrapper(x: Double) = new runtime.RichDouble(x) implicit def booleanWrapper(x: Boolean) = new runtime.RichBoolean(x) + // These eight implicits exist solely to exclude Null from the domain of + // the boxed types, so that e.g. "var x: Int = null" is a compile time + // error rather than a delayed null pointer exception by way of the + // conversion from java.lang.Integer. If defined in the same file as + // Integer2int, they would have higher priority because Null is a subtype + // of Integer. We balance that out and create conflict by moving the + // definition into the superclass. + // + // Caution: do not adjust tightrope tension without safety goggles in place. + implicit def Byte2byteNullConflict(x: Null): Byte = sys.error("value error") + implicit def Short2shortNullConflict(x: Null): Short = sys.error("value error") + implicit def Character2charNullConflict(x: Null): Char = sys.error("value error") + implicit def Integer2intNullConflict(x: Null): Int = sys.error("value error") + implicit def Long2longNullConflict(x: Null): Long = sys.error("value error") + implicit def Float2floatNullConflict(x: Null): Float = sys.error("value error") + implicit def Double2doubleNullConflict(x: Null): Double = sys.error("value error") + implicit def Boolean2booleanNullConflict(x: Null): Boolean = sys.error("value error") + implicit def genericWrapArray[T](xs: Array[T]): WrappedArray[T] = if (xs eq null) null else WrappedArray.make(xs) |