Skip to content

Commit 9a724c5

Browse files
committed
Mark classes compiled under -Ycc with a CaptureChecked annotation
1 parent e9157ec commit 9a724c5

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/Definitions.scala

+1
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ class Definitions {
972972
@tu lazy val BooleanBeanPropertyAnnot: ClassSymbol = requiredClass("scala.beans.BooleanBeanProperty")
973973
@tu lazy val BodyAnnot: ClassSymbol = requiredClass("scala.annotation.internal.Body")
974974
@tu lazy val CapabilityAnnot: ClassSymbol = requiredClass("scala.annotation.capability")
975+
@tu lazy val CaptureCheckedAnnot: ClassSymbol = requiredClass("scala.annotation.internal.CaptureChecked")
975976
@tu lazy val ChildAnnot: ClassSymbol = requiredClass("scala.annotation.internal.Child")
976977
@tu lazy val ContextResultCountAnnot: ClassSymbol = requiredClass("scala.annotation.internal.ContextResultCount")
977978
@tu lazy val ProvisionalSuperClassAnnot: ClassSymbol = requiredClass("scala.annotation.internal.ProvisionalSuperClass")

Diff for: compiler/src/dotty/tools/dotc/transform/PostTyper.scala

+7-7
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,13 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
388388
for parent <- impl.parents do
389389
Checking.checkTraitInheritance(parent.tpe.classSymbol, sym.asClass, parent.srcPos)
390390
// Add SourceFile annotation to top-level classes
391-
if sym.owner.is(Package)
392-
&& ctx.compilationUnit.source.exists
393-
&& sym != defn.SourceFileAnnot
394-
then
395-
val reference = ctx.settings.sourceroot.value
396-
val relativePath = util.SourceFile.relativePath(ctx.compilationUnit.source, reference)
397-
sym.addAnnotation(Annotation.makeSourceFile(relativePath))
391+
if sym.owner.is(Package) then
392+
if ctx.compilationUnit.source.exists && sym != defn.SourceFileAnnot then
393+
val reference = ctx.settings.sourceroot.value
394+
val relativePath = util.SourceFile.relativePath(ctx.compilationUnit.source, reference)
395+
sym.addAnnotation(Annotation.makeSourceFile(relativePath))
396+
if ctx.settings.Ycc.value && sym != defn.CaptureCheckedAnnot then
397+
sym.addAnnotation(Annotation(defn.CaptureCheckedAnnot))
398398
else (tree.rhs, sym.info) match
399399
case (rhs: LambdaTypeTree, bounds: TypeBounds) =>
400400
VarianceChecker.checkLambda(rhs, bounds)
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)