Skip to content

Commit 7d70584

Browse files
liufengyunmichelou
authored andcommitted
Add @Covers annotation
1 parent 38ddb1e commit 7d70584

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ class Definitions {
923923
@tu lazy val FunctionalInterfaceAnnot: ClassSymbol = requiredClass("java.lang.FunctionalInterface")
924924
@tu lazy val TargetNameAnnot: ClassSymbol = requiredClass("scala.annotation.targetName")
925925
@tu lazy val VarargsAnnot: ClassSymbol = requiredClass("scala.annotation.varargs")
926+
@tu lazy val CoversAnnot: ClassSymbol = requiredClass("scala.annotation.covers")
926927

927928
@tu lazy val JavaRepeatableAnnot: ClassSymbol = requiredClass("java.lang.annotation.Repeatable")
928929

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package scala.annotation
2+
3+
/** An annotation specifying that an extractor is irrefutable
4+
* if the scrutinee is a subtype of `T`.
5+
*
6+
* For example, the extractor `:+` covers non-empty list (`::[T]`):
7+
*
8+
* object :+ {
9+
* def unapply[T](l: List[T]): Option[(List[T], T)] @covers[::[T]] = ...
10+
* }
11+
*
12+
* def f(xs: List[Int]) =
13+
* xs match
14+
* case init :+ last => ()
15+
* case Nil => ()
16+
*
17+
* Therefore, the pattern match above is exhaustive.
18+
*/
19+
final class covers[T] extends StaticAnnotation

0 commit comments

Comments
 (0)