Skip to content

Commit 1b15fa6

Browse files
committed
Bugfix: Relax experimental inheritance criterion
We previously required that a class inheriting an @experimental class is itself @experimental. This is too strict. It should be OK to have the inheriting class be contained in an experimental scope. I.e. ``` @experimental class A @experimental object o: class B extends A ``` is now OK.
1 parent 18b8ff4 commit 1b15fa6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class CrossVersionChecks extends MiniPhase:
117117

118118
/** Check that classes extending experimental classes or nested in experimental classes have the @experimental annotation. */
119119
private def checkExperimentalInheritance(cls: ClassSymbol)(using Context): Unit =
120-
if !cls.isAnonymousClass && !cls.hasAnnotation(defn.ExperimentalAnnot) then
120+
if !cls.isAnonymousClass && !cls.isInExperimentalScope then
121121
cls.info.parents.find(_.typeSymbol.isExperimental) match
122122
case Some(parent) =>
123123
report.error(em"extension of experimental ${parent.typeSymbol} must have @experimental annotation", cls.srcPos)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import annotation.experimental
2+
@experimental class A
3+
@experimental object o:
4+
class B extends A

0 commit comments

Comments
 (0)