diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-05-12 18:30:53 +0200 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-05-12 18:30:53 +0200 |
commit | 89bacb9c25a58454ff1878e67f7ea07ffc8c269f (patch) | |
tree | 51f1ff6c66aebe1b6109b1cffcc2bb8e4cf760a3 /tests/pending/run/constrained-types.scala | |
parent | a0fa33deafbea1bf53edc068c5ed9db5592822f9 (diff) | |
download | dotty-89bacb9c25a58454ff1878e67f7ea07ffc8c269f.tar.gz dotty-89bacb9c25a58454ff1878e67f7ea07ffc8c269f.tar.bz2 dotty-89bacb9c25a58454ff1878e67f7ea07ffc8c269f.zip |
Run tests as they were in scala.
Diffstat (limited to 'tests/pending/run/constrained-types.scala')
-rw-r--r-- | tests/pending/run/constrained-types.scala | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/pending/run/constrained-types.scala b/tests/pending/run/constrained-types.scala new file mode 100644 index 000000000..7ec8f93d3 --- /dev/null +++ b/tests/pending/run/constrained-types.scala @@ -0,0 +1,84 @@ +/* Check on the processing of annotated types. Initially this tested + * asSeenFrom, but now it also tests packedType and the treatment + * of DeBruijn's . It runs the test using the interpreter so that + * the resulting annotated types can be printed out. + */ +import scala.tools.nsc.Settings +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ + +class Annot(obj: Any) extends annotation.Annotation with annotation.TypeConstraint + +class A { + val x = "hello" + val y: Int @Annot(x) = 10 + override def toString = "an A" +} + +val a = new A +val y = a.y // should rewrite "this.x" to "a.x" +var a2 = new A +val y2 = a2.y // should drop the annotation + +object Stuff { + val x = "hello" + val y : Int @Annot(x) = 10 +} + +val y = Stuff.y // should rewrite the annotation + +class B { + val y: Int @Annot(Stuff.x) = 10 + override def toString = "a B" +} + +val b = new B +val y = b.y // should keep the annotation +def m(x: String): String @Annot(x) = x + +val three = "three" +val three2 = m(three:three.type) // should change x to three +var four = "four" +val four2 = m(four) // should have an existential bound +val four3 = four2 // should have the same type as four2 +val stuff = m("stuff") // should not crash + +class peer extends annotation.Annotation // should not crash + +class NPE[T <: NPE[T] @peer] // should not crash + +def m = { + val x = "three" + val y : String @Annot(x) = x + y +} // x should not escape the local scope with a narrow type + +def n(y: String) = { + def m(x: String) : String @Annot(x) = { + (if (x == "") + m("default") + else + x) + } + m("stuff".stripMargin) +} // x should be existentially bound + +class rep extends annotation.Annotation { } + +object A { val x = "hello" : String @ rep } + +val y = a.x // should drop the annotation + +val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message +""" + + override def transformSettings(s: Settings): Settings = { + s.Xexperimental.value = true + s.deprecation.value = true + // when running that compiler, give it a scala-library to the classpath + s.classpath.value = sys.props("java.class.path") + s + } +} |