diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 37bdde5b0559..6e9d4caa7f6a 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -1186,7 +1186,7 @@ object RefChecks { /** Check that classes extending experimental classes or nested in experimental classes have the @experimental annotation. */ private def checkExperimentalInheritance(cls: ClassSymbol)(using Context): Unit = - if !cls.hasAnnotation(defn.ExperimentalAnnot) then + if !cls.isAnonymousClass && !cls.hasAnnotation(defn.ExperimentalAnnot) then cls.info.parents.find(_.typeSymbol.isExperimental) match case Some(parent) => report.error(em"extension of experimental ${parent.typeSymbol} must have @experimental annotation", cls.srcPos) diff --git a/tests/neg-custom-args/no-experimental/i13091.scala b/tests/neg-custom-args/no-experimental/i13091.scala new file mode 100644 index 000000000000..b2e0c1844540 --- /dev/null +++ b/tests/neg-custom-args/no-experimental/i13091.scala @@ -0,0 +1,5 @@ +import annotation.experimental + +@experimental class Foo // error: use of @experimental is experimental ... + +def test: Unit = new Foo // error: class Foo is marked @experimental ... diff --git a/tests/pos/i13091.scala b/tests/pos/i13091.scala new file mode 100644 index 000000000000..fa255cd6c08f --- /dev/null +++ b/tests/pos/i13091.scala @@ -0,0 +1,3 @@ +import annotation.experimental +@experimental class Foo +val foo = new Foo