-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `@exerimental` annotation marks definitions as _experimental_ feature. These can be used in the same situattions where `languange.experimental` can be used.
- Loading branch information
1 parent
183ec08
commit 4aaca69
Showing
12 changed files
with
135 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
compiler/src/dotty/tools/dotc/transform/CheckExperimental.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package dotty.tools.dotc | ||
package transform | ||
|
||
import core._ | ||
import dotty.tools.dotc.transform.MegaPhase._ | ||
import Flags._ | ||
import Contexts._ | ||
import Types._ | ||
import Symbols._ | ||
import SymUtils._ | ||
import Decorators._ | ||
import config.Feature | ||
import util.SrcPos | ||
|
||
/** | ||
*/ | ||
class CheckExperimental extends MiniPhase: | ||
import ast.tpd._ | ||
|
||
override def phaseName: String = "checkExperimental" | ||
|
||
override def transformIdent(tree: Ident)(using Context): Tree = | ||
checkExperimental(tree) | ||
|
||
override def transformSelect(tree: Select)(using Context): Tree = | ||
checkExperimental(tree) | ||
|
||
override def transformTypeTree(tree: TypeTree)(using Context): Tree = | ||
checkExperimentalTypes(tree) | ||
|
||
override def transformOther(tree: Tree)(using Context): Tree = | ||
tree match | ||
case _: TypeTree => checkExperimentalTypes(tree) // TODO: why was transformTypeTree not called? | ||
case _ => tree | ||
|
||
private def checkExperimental(tree: Tree)(using Context): tree.type = | ||
if tree.symbol.isExperimental && !tree.symbol.isConstructor then | ||
Feature.checkExperimentalFeature(tree.symbol.show, tree) | ||
tree | ||
|
||
private def checkExperimentalTypes(tree: Tree)(using Context): tree.type = | ||
val checker = new TypeTraverser: | ||
def traverse(tp: Type): Unit = | ||
if tp.typeSymbol.isExperimental then | ||
Feature.checkExperimentalFeature(tp.typeSymbol.show, tree) | ||
else | ||
traverseChildren(tp) | ||
if !tree.span.isSynthetic then // avoid double errors | ||
checker.traverse(tree.tpe) | ||
tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package scala.annotation | ||
|
||
/** An annotation that can be used to mark a definition as experimental. */ | ||
class experimental extends StaticAnnotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/neg-custom-args/no-experimental/experimentalAnnotation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import scala.annotation.experimental | ||
|
||
@experimental | ||
val x = () | ||
|
||
@experimental | ||
def f() = () | ||
|
||
@experimental | ||
class A: | ||
def f() = 1 | ||
|
||
class B extends A: // error | ||
override def f() = 2 | ||
|
||
@experimental | ||
type X | ||
|
||
@experimental | ||
object X: | ||
def fx() = 1 | ||
|
||
def test( | ||
p1: A, // error | ||
p2: X, // error | ||
p3: List[A], // error | ||
): Unit = | ||
f() // error | ||
x // error | ||
new A // error | ||
new B // error | ||
X.fx() // error | ||
import X.fx | ||
fx() // error | ||
val i1 = identity[X] // error | ||
val i2 = identity[A] // error | ||
val a: A = ??? // error | ||
val b: B = ??? // error | ||
a.f() // error | ||
b.f() // error | ||
() |
8 changes: 8 additions & 0 deletions
8
tests/neg-custom-args/no-experimental/experimentalnline.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import scala.annotation.experimental | ||
|
||
@experimental | ||
inline def g() = () | ||
|
||
def test: Unit = | ||
g() // errors | ||
() |