Skip to content

Commit 9033e0c

Browse files
committed
Mark classes compiled under -Ycc with a CaptureChecked annotation
1 parent 91299b2 commit 9033e0c

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
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 BooleanBeanPropertyAnnot: ClassSymbol = requiredClass("scala.beans.BooleanBeanProperty")
924924
@tu lazy val BodyAnnot: ClassSymbol = requiredClass("scala.annotation.internal.Body")
925925
@tu lazy val CapabilityAnnot: ClassSymbol = requiredClass("scala.annotation.capability")
926+
@tu lazy val CaptureCheckedAnnot: ClassSymbol = requiredClass("scala.annotation.internal.CaptureChecked")
926927
@tu lazy val ChildAnnot: ClassSymbol = requiredClass("scala.annotation.internal.Child")
927928
@tu lazy val ContextResultCountAnnot: ClassSymbol = requiredClass("scala.annotation.internal.ContextResultCount")
928929
@tu lazy val ProvisionalSuperClassAnnot: ClassSymbol = requiredClass("scala.annotation.internal.ProvisionalSuperClass")

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,13 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
370370
for parent <- impl.parents do
371371
Checking.checkTraitInheritance(parent.tpe.classSymbol, sym.asClass, parent.srcPos)
372372
// Add SourceFile annotation to top-level classes
373-
if sym.owner.is(Package)
374-
&& ctx.compilationUnit.source.exists
375-
&& sym != defn.SourceFileAnnot
376-
then
377-
val reference = ctx.settings.sourceroot.value
378-
val relativePath = util.SourceFile.relativePath(ctx.compilationUnit.source, reference)
379-
sym.addAnnotation(Annotation.makeSourceFile(relativePath))
373+
if sym.owner.is(Package) then
374+
if ctx.compilationUnit.source.exists && sym != defn.SourceFileAnnot then
375+
val reference = ctx.settings.sourceroot.value
376+
val relativePath = util.SourceFile.relativePath(ctx.compilationUnit.source, reference)
377+
sym.addAnnotation(Annotation.makeSourceFile(relativePath))
378+
if ctx.settings.Ycc.value && sym != defn.CaptureCheckedAnnot then
379+
sym.addAnnotation(Annotation(defn.CaptureCheckedAnnot))
380380
else (tree.rhs, sym.info) match
381381
case (rhs: LambdaTypeTree, bounds: TypeBounds) =>
382382
VarianceChecker.checkLambda(rhs, bounds)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package scala.annotation
2+
package internal
3+
4+
/** A marker annotation on a toplevel class that indicates
5+
* that the class was checked under -Ycc
6+
*/
7+
class CaptureChecked extends StaticAnnotation
8+

0 commit comments

Comments
 (0)