Skip to content

Commit

Permalink
Do not add @experimental annotations to nested definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed May 3, 2021
1 parent 8294257 commit 9d75466
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
3 changes: 0 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ object SymUtils:
|| self.hasAnnotation(defn.ExperimentalAnnot)
|| (self.maybeOwner.isClass && self.owner.hasAnnotation(defn.ExperimentalAnnot))

def isNestedInExperimental(using Context): Boolean =
self.ownersIterator.drop(1).exists(_.hasAnnotation(defn.ExperimentalAnnot))

/** The declared self type of this class, as seen from `site`, stripping
* all refinements for opaque types.
*/
Expand Down
13 changes: 4 additions & 9 deletions compiler/src/dotty/tools/dotc/util/Experimental.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ object Experimental:
checker.traverse(tree.tpe)

def annotateExperimental(sym: Symbol)(using Context): Unit =
if sym.isClass && !sym.hasAnnotation(defn.ExperimentalAnnot) then
// Add @experimental annotation to all classes nested in an experimental definition
if !sym.owner.is(Package) && sym.isNestedInExperimental then
sym.addAnnotation(defn.ExperimentalAnnot)

if sym.is(Enum) && sym.hasAnnotation(defn.ExperimentalAnnot) then
// Add @experimental annotation to enum class definitions
val compSym = sym.companionClass
if compSym.is(Enum) && compSym.hasAnnotation(defn.ExperimentalAnnot) then
sym.addAnnotation(defn.ExperimentalAnnot)
sym.companionModule.addAnnotation(defn.ExperimentalAnnot)
val compMod = sym.companionModule.moduleClass
compMod.addAnnotation(defn.ExperimentalAnnot)
compMod.companionModule.addAnnotation(defn.ExperimentalAnnot)
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ trait ExpSAM {
def bar(f: ExpSAM): Unit = {} // error

@experimental // error
enum E:
enum E: // error
case A
case B
case B // error

def test(
p1: A, // error
Expand Down

0 comments on commit 9d75466

Please sign in to comment.