Skip to content

Commit cbff7a4

Browse files
committed
An alternative way to refer to * with no -Ycc set
1 parent 913bc49 commit cbff7a4

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ class CheckCaptures extends Recheck, SymTransformer:
690690

691691
/** Destruct a capturing type `tp` to a tuple (cs, tp0, boxed),
692692
* where `tp0` is not a capturing type.
693-
*
693+
*
694694
* If `tp` is a nested capturing type, the return tuple always represents
695695
* the innermost capturing type. The outer capture annotations can be
696696
* reconstructed with the returned function.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ class Definitions {
10231023
@tu lazy val RequiresCapabilityAnnot: ClassSymbol = requiredClass("scala.annotation.internal.requiresCapability")
10241024
@tu lazy val RetainsAnnot: ClassSymbol = requiredClass("scala.annotation.retains")
10251025
@tu lazy val RetainsByNameAnnot: ClassSymbol = requiredClass("scala.annotation.retainsByName")
1026+
@tu lazy val RetainsUniversalAnnot: ClassSymbol = requiredClass("scala.annotation.retainsUniversal")
10261027

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

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,9 +2669,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
26692669
end typedPackageDef
26702670

26712671
def typedAnnotated(tree: untpd.Annotated, pt: Type)(using Context): Tree = {
2672-
val annot1 = typedExpr(tree.annot, defn.AnnotationClass.typeRef)
2673-
if Annotations.annotClass(annot1) == defn.NowarnAnnot then
2672+
var annot1 = typedExpr(tree.annot, defn.AnnotationClass.typeRef)
2673+
val annotCls = Annotations.annotClass(annot1)
2674+
if annotCls == defn.NowarnAnnot then
26742675
registerNowarn(annot1, tree)
2676+
else if annotCls == defn.RetainsUniversalAnnot then
2677+
annot1 = typedExpr(
2678+
untpd.New(
2679+
untpd.TypeTree(defn.RetainsAnnot.typeRef),
2680+
(untpd.ref(defn.captureRoot) :: Nil) :: Nil).withSpan(tree.annot.span),
2681+
defn.AnnotationClass.typeRef)
26752682
val arg1 = typed(tree.arg, pt)
26762683
if (ctx.mode is Mode.Type) {
26772684
val cls = annot1.symbol.maybeOwner

library/src/scala/annotation/retains.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ package scala.annotation
1414
// @experimental // suppressed so we can use in compiler
1515
class retains(xs: Any*) extends annotation.StaticAnnotation
1616

17+
// @experimental // suppressed so we can use in compiler
18+
class retainsUniversal extends annotation.StaticAnnotation
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import annotation.retainsUniversal
2+
3+
val foo: Int => Int = x => x
4+
val bar: (Int -> Int) @retainsUniversal = foo
5+
val baz: {*} Int -> Int = bar
6+
7+

0 commit comments

Comments
 (0)