Disables NotNull checking unless -Ynotnull is given. Closes #3568,

review by odersky.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@22303 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
extempore 2010-06-15 21:14:14 +00:00
parent 68d6108ff5
commit c6abb55305
3 changed files with 53 additions and 3 deletions

View File

@ -138,6 +138,7 @@ trait ScalaSettings extends AbsScalaSettings with StandardScalaSettings {
val Ycompletion = BooleanSetting ("-Ycompletion-debug", "Trace all tab completion activity.")
val Ypmatnaive = BooleanSetting ("-Ypmat-naive", "Desugar matches as naively as possible..")
val Yjenkins = BooleanSetting ("-Yjenkins-hashCodes", "Use jenkins hash algorithm for case class generated hashCodes.")
val Ynotnull = BooleanSetting ("-Ynotnull", "Enable the experimental and incomplete scala.NotNull")
// Warnings
val Ywarndeadcode = BooleanSetting ("-Ywarn-dead-code", "Emit warnings for dead code")

View File

@ -385,9 +385,12 @@ trait Types extends reflect.generic.Types { self: SymbolTable =>
* the empty list for all other types */
def boundSyms: List[Symbol] = List()
/** Mixin a NotNull trait unless type already has one */
def notNull: Type =
if (isNotNull || phase.erasedTypes) this else NotNullType(this)
/** Mixin a NotNull trait unless type already has one
* ...if the option is given, since it is causing typing bugs.
*/
def notNull: Type =
if (!settings.Ynotnull.value || isNotNull || phase.erasedTypes) this
else NotNullType(this)
/** Replace formal type parameter symbols with actual type arguments.
*

View File

@ -0,0 +1,46 @@
import scala.annotation._
import scala.annotation.unchecked._
import scala.collection._
package object buffer {
val broken = new ArrayVec2() // commenting out this line causes the file to compile.
val works = Class.forName("buffer.ArrayVec2").newInstance().asInstanceOf[ArrayVec2]
}
package buffer {
object Main {
// ArrayVec2 can be compiled, instantiated and used.
def main(args: Array[String]) { println(works) }
}
trait ElemType { type Element; type Component <: ElemType }
trait Float1 extends ElemType { type Element = Float; type Component = Float1}
class Vec2 extends ElemType { type Element = Vec2; type Component = Float1 }
abstract class BaseSeq[T <: ElemType, E]
extends IndexedSeq[E] with IndexedSeqOptimized[E, IndexedSeq[E]] {
def length = 1
def apply(i: Int) :E
}
abstract class GenericSeq[T <: ElemType] extends BaseSeq[T, T#Element]
trait DataArray[T <: ElemType] extends BaseSeq[T, T#Element]
trait DataView[T <: ElemType] extends BaseSeq[T, T#Element]
abstract class BaseFloat1 extends BaseSeq[Float1, Float]
class ArrayFloat1 extends BaseFloat1 with DataArray[Float1] {
def apply(i: Int) :Float = 0f
}
class ViewFloat1 extends BaseFloat1 with DataView[Float1] {
def apply(i: Int) :Float = 0f
}
class ArrayVec2(val backingSeq: ArrayFloat1)
extends GenericSeq[Vec2] with DataArray[Vec2] {
def this() = this(new ArrayFloat1)
def apply(i: Int) :Vec2 = null
}
}