-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict allowed trees in annotations
- Loading branch information
Showing
22 changed files
with
199 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-- Error: tests/neg/annot-invalid.scala:4:21 --------------------------------------------------------------------------- | ||
4 | val x1: Int @annot(new Object {}) = 0 // error | ||
| ^^^^^^^^^^^^^ | ||
| Implementation restriction: not a valid annotation argument. | ||
| Argument: { | ||
| final class $anon() extends Object() {} | ||
| new $anon():Object | ||
| } | ||
| Type: Object | ||
-- Error: tests/neg/annot-invalid.scala:5:21 --------------------------------------------------------------------------- | ||
5 | val x2: Int @annot({val x = 1}) = 0 // error | ||
| ^^^^^^^^^^^ | ||
| Implementation restriction: not a valid annotation argument. | ||
| Argument: { | ||
| val x: Int = 1 | ||
| () | ||
| } | ||
| Type: Unit | ||
-- Error: tests/neg/annot-invalid.scala:6:21 --------------------------------------------------------------------------- | ||
6 | val x3: Int @annot((x: Int) => x) = 0 // error | ||
| ^^^^^^^^^^^^^ | ||
| Implementation restriction: not a valid annotation argument. | ||
| Argument: (x: Int) => x | ||
| Type: Int => Int | ||
-- Error: tests/neg/annot-invalid.scala:8:9 ---------------------------------------------------------------------------- | ||
8 | @annot(new Object {}) val y1: Int = 0 // error | ||
| ^^^^^^^^^^^^^ | ||
| Implementation restriction: not a valid annotation argument. | ||
| Argument: { | ||
| final class $anon() extends Object() {} | ||
| new $anon():Object | ||
| } | ||
| Type: Object | ||
-- Error: tests/neg/annot-invalid.scala:9:9 ---------------------------------------------------------------------------- | ||
9 | @annot({val x = 1}) val y2: Int = 0 // error | ||
| ^^^^^^^^^^^ | ||
| Implementation restriction: not a valid annotation argument. | ||
| Argument: { | ||
| val x: Int = 1 | ||
| () | ||
| } | ||
| Type: Unit | ||
-- Error: tests/neg/annot-invalid.scala:10:9 --------------------------------------------------------------------------- | ||
10 | @annot((x: Int) => x) val y3: Int = 0 // error | ||
| ^^^^^^^^^^^^^ | ||
| Implementation restriction: not a valid annotation argument. | ||
| Argument: (x: Int) => x | ||
| Type: Int => Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class annot[T](arg: T) extends scala.annotation.Annotation | ||
|
||
def main = | ||
val x1: Int @annot(new Object {}) = 0 // error | ||
val x2: Int @annot({val x = 1}) = 0 // error | ||
val x3: Int @annot((x: Int) => x) = 0 // error | ||
|
||
@annot(new Object {}) val y1: Int = 0 // error | ||
@annot({val x = 1}) val y2: Int = 0 // error | ||
@annot((x: Int) => x) val y3: Int = 0 // error | ||
|
||
() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import scala.annotation.Annotation | ||
|
||
class AnAnnotation(function: Int => String) extends Annotation | ||
|
||
@AnAnnotation(_.toString) // error: not a valid annotation | ||
val a = 1 | ||
@AnAnnotation(_.toString.length.toString) // error: not a valid annotation | ||
val b = 2 | ||
|
||
def test = | ||
@AnAnnotation(_.toString) // error: not a valid annotation | ||
val a = 1 | ||
@AnAnnotation(_.toString.length.toString) // error: not a valid annotation | ||
val b = 2 | ||
a + b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class A(a: Any) extends annotation.StaticAnnotation | ||
@A({val x = 0}) trait B // error: not a valid annotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class A(a: Any) extends annotation.StaticAnnotation | ||
@A({def x = 0}) trait B // error: not a valid annotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
final class fooAnnot[T](member: T) extends scala.annotation.StaticAnnotation // must have type parameter | ||
|
||
@fooAnnot(new RecAnnotated {}) // must pass instance of anonymous subclass | ||
@fooAnnot(new RecAnnotated {}) // error: not a valid annotation | ||
trait RecAnnotated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class foo(x: Any) extends annotation.StaticAnnotation | ||
|
||
@foo(new AnyRef { }) trait A // error: not a valid annotation |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// `FirstTransform.toTypeTree` creates `Annotated` nodes whose `annot` are | ||
// `Ident`s, not annotation instances. This is relevant for `Checking.checkAnnot`. | ||
// | ||
// See also: | ||
// - tests/run/t2755.scala | ||
// - tests/neg/i13044.scala | ||
|
||
def f(a: Array[?]) = | ||
a match | ||
case x: Array[?] => () | ||
|
||
def f2(t: Tuple) = | ||
t match | ||
case _: (t *: ts) => () | ||
case _ => () | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class annot[T](arg: T) extends scala.annotation.Annotation | ||
|
||
def main = | ||
val n: Int = 0 | ||
def f(x: Any): Unit = () | ||
|
||
val x1: Int @annot(42) = 0 | ||
val x2: Int @annot("hello") = 0 | ||
val x3: Int @annot(classOf[Int]) = 0 | ||
val x4: Int @annot(Array(1,2)) = 0 | ||
val x5: Int @annot(Array(Array(1,2),Array(3,4))) = 0 | ||
val x6: Int @annot((1,2)) = 0 | ||
val x7: Int @annot((1,2,3)) = 0 | ||
val x8: Int @annot(((1,2),3)) = 0 | ||
val x9: Int @annot(((1,2),(3,4))) = 0 | ||
val x10: Int @annot(Symbol("hello")) = 0 | ||
val x11: Int @annot(n + 1) = 0 | ||
val x12: Int @annot(f(2)) = 0 | ||
val x13: Int @annot(throw new Error()) = 0 | ||
val x14: Int @annot(42: Double) = 0 | ||
|
||
@annot(42) val y1: Int = 0 | ||
@annot("hello") val y2: Int = 0 | ||
@annot(classOf[Int]) val y3: Int = 0 | ||
@annot(Array(1,2)) val y4: Int = 0 | ||
@annot(Array(Array(1,2),Array(3,4))) val y5: Int = 0 | ||
@annot((1,2)) val y6: Int = 0 | ||
@annot((1,2,3)) val y7: Int = 0 | ||
@annot(((1,2),3)) val y8: Int = 0 | ||
@annot(((1,2),(3,4))) val y9: Int = 0 | ||
@annot(Symbol("hello")) val y10: Int = 0 | ||
@annot(n + 1) val y11: Int = 0 | ||
@annot(f(2)) val y12: Int = 0 | ||
@annot(throw new Error()) val y13: Int = 0 | ||
@annot(42: Double) val y14: Int = 0 | ||
|
||
() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.