Skip to content

Commit 9d75466

Browse files
committed
Do not add @experimental annotations to nested definitions
1 parent 8294257 commit 9d75466

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,6 @@ object SymUtils:
266266
|| self.hasAnnotation(defn.ExperimentalAnnot)
267267
|| (self.maybeOwner.isClass && self.owner.hasAnnotation(defn.ExperimentalAnnot))
268268

269-
def isNestedInExperimental(using Context): Boolean =
270-
self.ownersIterator.drop(1).exists(_.hasAnnotation(defn.ExperimentalAnnot))
271-
272269
/** The declared self type of this class, as seen from `site`, stripping
273270
* all refinements for opaque types.
274271
*/

compiler/src/dotty/tools/dotc/util/Experimental.scala

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,8 @@ object Experimental:
3333
checker.traverse(tree.tpe)
3434

3535
def annotateExperimental(sym: Symbol)(using Context): Unit =
36-
if sym.isClass && !sym.hasAnnotation(defn.ExperimentalAnnot) then
37-
// Add @experimental annotation to all classes nested in an experimental definition
38-
if !sym.owner.is(Package) && sym.isNestedInExperimental then
39-
sym.addAnnotation(defn.ExperimentalAnnot)
40-
36+
if sym.is(Enum) && sym.hasAnnotation(defn.ExperimentalAnnot) then
4137
// Add @experimental annotation to enum class definitions
42-
val compSym = sym.companionClass
43-
if compSym.is(Enum) && compSym.hasAnnotation(defn.ExperimentalAnnot) then
44-
sym.addAnnotation(defn.ExperimentalAnnot)
45-
sym.companionModule.addAnnotation(defn.ExperimentalAnnot)
38+
val compMod = sym.companionModule.moduleClass
39+
compMod.addAnnotation(defn.ExperimentalAnnot)
40+
compMod.companionModule.addAnnotation(defn.ExperimentalAnnot)

tests/neg-custom-args/no-experimental/experimentalAnnotation.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ trait ExpSAM {
5959
def bar(f: ExpSAM): Unit = {} // error
6060

6161
@experimental // error
62-
enum E:
62+
enum E: // error
6363
case A
64-
case B
64+
case B // error
6565

6666
def test(
6767
p1: A, // error

0 commit comments

Comments
 (0)