Skip to content

Commit e1449b6

Browse files
committed
Drop experimental inheritance checking
IMO it's a foot gun that prevents useful idioms. Concretely I have an @experimental marker trait `@caps.Pure` that classes can inherit. So far, there was no way to do that except if the inheriting class is also @experimental. This requirement was unconditional. It did not help to be in an experimental scope or to use a snapshot compiler version. This basically means that @experimental base traits are useless, unless one is prepared to pollute the codebase with sprinkling experimental over all inheriting classes. On the other hand, I see no useful property that is established by this restriction. The (now deleted) documentation is also silent about the motivation of all this.
1 parent d8a6751 commit e1449b6

File tree

5 files changed

+2
-88
lines changed

5 files changed

+2
-88
lines changed

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,6 @@ class CrossVersionChecks extends MiniPhase:
115115
}
116116
}
117117

118-
/** Check that classes extending experimental classes or nested in experimental classes have the @experimental annotation. */
119-
private def checkExperimentalInheritance(cls: ClassSymbol)(using Context): Unit =
120-
if !cls.isAnonymousClass && !cls.isInExperimentalScope then
121-
cls.info.parents.find(_.typeSymbol.isExperimental) match
122-
case Some(parent) =>
123-
report.error(em"extension of experimental ${parent.typeSymbol} must have @experimental annotation", cls.srcPos)
124-
case _ =>
125-
end checkExperimentalInheritance
126-
127118
override def transformValDef(tree: ValDef)(using Context): ValDef =
128119
checkDeprecatedOvers(tree)
129120
checkExperimentalAnnots(tree.symbol)
@@ -136,12 +127,6 @@ class CrossVersionChecks extends MiniPhase:
136127
checkExperimentalSignature(tree.symbol, tree)
137128
tree
138129

139-
override def transformTemplate(tree: Template)(using Context): Tree =
140-
val cls = ctx.owner.asClass
141-
checkExperimentalInheritance(cls)
142-
checkExperimentalAnnots(cls)
143-
tree
144-
145130
override def transformIdent(tree: Ident)(using Context): Ident = {
146131
checkUndesiredProperties(tree.symbol, tree.srcPos)
147132
tree

docs/_docs/reference/other-new-features/experimental-defs.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Experimental definitions can only be referenced in an experimental scope. Experi
216216

217217
<details>
218218
<summary>Example 1</summary>
219-
219+
220220
```scala
221221
import scala.annotation.experimental
222222

@@ -242,7 +242,7 @@ Experimental definitions can only be referenced in an experimental scope. Experi
242242
}
243243
}
244244
```
245-
245+
246246
</details>
247247

248248
5. Annotations of an experimental definition are in experimental scopes. Examples:
@@ -270,13 +270,6 @@ Can use the `-Yno-experimental` compiler flag to disable it and run as a proper
270270

271271
In any other situation, a reference to an experimental definition will cause a compilation error.
272272

273-
## Experimental inheritance
274-
275-
All subclasses of an experimental `class` or `trait` must be marked as [`@experimental`](https://scala-lang.org/api/3.x/scala/annotation/experimental.html) even if they are in an experimental scope.
276-
Anonymous classes and SAMs of experimental classes are considered experimental.
277-
278-
We require explicit annotations to make sure we do not have completion or cycles issues with nested classes. This restriction could be relaxed in the future.
279-
280273
## Experimental overriding
281274

282275
For an overriding member `M` and overridden member `O`, if `O` is non-experimental then `M` must be non-experimental.

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/neg/experimentalInheritance.scala

Lines changed: 0 additions & 44 deletions
This file was deleted.

tests/neg/experimentalInheritance2.scala

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)