diff options
author | Paul Phillips <paulp@improving.org> | 2013-01-14 23:29:50 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-01-26 11:19:36 -0800 |
commit | 832fc9a67e5aa85bdde61883527d3ac9554094d7 (patch) | |
tree | b5bc08f2ef57331efa66c956112bface14cd530f /test/files/pos/annotations2.scala | |
parent | 72f36cbc80d5667c5ada3b7c0fe60435a4b202ad (diff) | |
download | scala-832fc9a67e5aa85bdde61883527d3ac9554094d7.tar.gz scala-832fc9a67e5aa85bdde61883527d3ac9554094d7.tar.bz2 scala-832fc9a67e5aa85bdde61883527d3ac9554094d7.zip |
SI-2577, SI-6860: annotation type inference.
This is less than ideal:
scala> class Bippy[T] extends annotation.StaticAnnotation
defined class Bippy
scala> def f: Int @Bippy = 5
f: Int @Bippy[T]
Turns out we can infer such types. Now it says:
scala> def f: Int @Bippy = 5
f: Int @Bippy[Nothing]
This should put to rest many an issue with parameterized
annotations.
Diffstat (limited to 'test/files/pos/annotations2.scala')
-rw-r--r-- | test/files/pos/annotations2.scala | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/files/pos/annotations2.scala b/test/files/pos/annotations2.scala new file mode 100644 index 0000000000..3bce7f8ac4 --- /dev/null +++ b/test/files/pos/annotations2.scala @@ -0,0 +1,31 @@ + +class B[T](x: (T, T)) { + def this(xx: (T, Any, Any)) = this((xx._1, xx._1)) +} +class BAnn[T](x: (T, T)) extends scala.annotation.StaticAnnotation { + def this(xx: (T, Any, Any)) = this((xx._1, xx._1)) +} +class CAnn[T](x: (T, T)) extends scala.annotation.StaticAnnotation { + def this(xx: Class[T]) = this((xx.newInstance(), xx.newInstance())) +} + +class A1 { + val b1 = new B((1, 2, 3)) + val b2 = new B((1, 2)) + val b3 = new B[Int]((1, 2, 3)) + val b4 = new B[Int]((1, 2)) +} + +class A2 { + @BAnn((1, 2, 3)) val b1 = null + @BAnn((1, 2)) val b2 = null + @BAnn[Int]((1, 2, 3)) val b3 = null + @BAnn[Int]((1, 2)) val b4 = null +} + +class A3 { + @CAnn(classOf[Int]) val b1 = null + @CAnn((1, 2)) val b2 = null + @CAnn[Int](classOf[Int]) val b3 = null + @CAnn[Int]((1, 2)) val b4 = null +} |