constrained-types.check
来自「JAVA 语言的函数式编程扩展」· CHECK 代码 · 共 137 行
CHECK
137 行
class Annot(obj: Any) extends Annotation with TypeConstraintdefined class Annot-----class A { val x = "hello" val y: Int @Annot(x) = 10 override def toString = "an A"} defined class A-----val a = new Aa: A = an A-----val y = a.y // should rewrite "this.x" to "a.x" y: Int @Annot(a.x) = 10-----var a2 = new Aa2: A = an A-----val y2 = a2.y // should drop the annotationy2: Int = 10-----object Stuff { val x = "hello" val y : Int @Annot(x) = 10}defined module Stuff-----val y = Stuff.y // should rewrite the annotationy: Int @Annot(Stuff.x) = 10-----class B { val y: Int @Annot(Stuff.x) = 10 override def toString = "a B"}defined class B-----val b = new Bb: B = a B-----val y = b.y // should keep the annotationy: Int @Annot(Stuff.x) = 10-----def m(x: String): String @Annot(x) = x // m should be annotated with a debruijnm: (x$0:String)String @Annot(x)-----val three = "three"three: java.lang.String = three-----val three2 = m(three:three.type) // should change x to threethree2: String @Annot(three) = three-----var four = "four"four: java.lang.String = four-----val four2 = m(four) // should have an existential boundfour2: String @Annot(x) forSome { val x: java.lang.String } = four-----val four3 = four2 // should have the same type as four2four3: String @Annot(x) forSome { val x: java.lang.String } = four-----val stuff = m("stuff") // should not crashstuff: String @Annot("stuff") = stuff-----class peer extends Annotation // should not crashdefined class peer-----class NPE[T <: NPE[T] @peer] // should not crasherror: illegal cyclic reference involving class NPE-----def m = { val x = "three" val y : String @Annot(x) = x y} // x should be existentially boundm: String @Annot(x) forSome { val x: java.lang.String }-----def n(y: String) = { def m(x: String) : String @Annot(x) = { (if (x == "") m("default") else x) } m("stuff".stripMargin)} // x should be existentially boundn: (String)String @Annot(x) forSome { val x: String }-----class rep extends Annotationdefined class rep-----object A { val x = "hello" : String @ rep }defined module A-----val y = a.x // should drop the annotationy: java.lang.String = hello-----val x = 3 : Int @Annot(e+f+g+h) //should have a graceful error message<console>:5: error: not found: value e val x = 3 : Int @Annot(e+f+g+h) //should have a graceful error message ^-----class Where(condition: Boolean) extends Annotationdefined class Where-----val x : Int @Where(self > 0 && self < 100) = 3x: Int @Where(self.>(0).&&(self.<(100))) = 3-----
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?