-
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
090b1b1
commit 2a7d472
Showing
16 changed files
with
184 additions
and
20 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package dotty.tools.dotc | ||
package util | ||
|
||
import dotty.tools.dotc.ast.tpd | ||
import dotty.tools.dotc.ast.Trees._ | ||
import dotty.tools.dotc.config.Feature | ||
import dotty.tools.dotc.core.Contexts._ | ||
import dotty.tools.dotc.core.Symbols._ | ||
import dotty.tools.dotc.core.Types._ | ||
import dotty.tools.dotc.core.Flags._ | ||
import dotty.tools.dotc.transform.SymUtils._ | ||
|
||
object Experimental: | ||
import tpd._ | ||
|
||
def checkExperimental(tree: Tree)(using Context): Unit = | ||
if tree.symbol.isExperimental | ||
&& !tree.symbol.isConstructor // already reported on the class | ||
&& !tree.symbol.is(ModuleClass) // already reported on the module | ||
&& (tree.span.exists || tree.symbol != defn.ExperimentalAnnot) // already reported on inferred annotations | ||
then | ||
Feature.checkExperimentalFeature(tree.symbol.show, tree) | ||
|
||
def checkExperimentalTypes(tree: Tree)(using Context): Unit = | ||
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) |
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,14 @@ | ||
package scala.annotation | ||
|
||
/** An annotation that can be used to mark a definition as experimental. | ||
* | ||
* This class is experimental as well as if it was defined as | ||
* ```scala | ||
* @experimental | ||
* class experimental extends StaticAnnotation | ||
* ``` | ||
* | ||
* @syntax markdown | ||
*/ | ||
// @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
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
76 changes: 76 additions & 0 deletions
76
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,76 @@ | ||
import scala.annotation.experimental | ||
|
||
@experimental // error | ||
val x = () | ||
|
||
@experimental // error | ||
def f() = () | ||
|
||
@experimental // error | ||
class A: | ||
def f() = 1 | ||
|
||
class B extends A: // error | ||
override def f() = 2 | ||
|
||
@experimental // error | ||
type X | ||
|
||
@experimental // error | ||
object X: | ||
def fx() = 1 // error | ||
|
||
class C: | ||
@experimental // error | ||
def f() = 1 | ||
|
||
class D extends C: | ||
override def f() = 2 | ||
|
||
trait A2: | ||
@experimental // error | ||
def f(): Int | ||
|
||
trait B2: | ||
def f(): Int | ||
|
||
class C2 extends A2, B2: | ||
def f(): Int = 1 | ||
|
||
object Extractor1: | ||
def unapply(s: Any): Option[A] = ??? // error | ||
|
||
object Extractor2: | ||
@experimental // error | ||
def unapply(s: Any): Option[Int] = ??? | ||
|
||
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 // error | ||
fx() // error | ||
val i1 = identity[X] // error // error | ||
val i2 = identity[A] // error // error | ||
val a: A = ??? // error | ||
val b: B = ??? // error | ||
val c: C = ??? | ||
val d: D = ??? | ||
val c2: C2 = ??? | ||
a.f() // error | ||
b.f() // error | ||
c.f() // error | ||
d.f() // error | ||
c2.f() // ok because B2.f is a stable API | ||
() | ||
|
||
??? match | ||
case _: A => // error // error | ||
case Extractor1(_) => // error | ||
case Extractor2(_) => // error |
1 change: 1 addition & 0 deletions
1
tests/neg-custom-args/no-experimental/experimentalExperimental.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 @@ | ||
class MyExperimentalAnnot extends scala.annotation.experimental // 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 // error | ||
inline def g() = () | ||
|
||
def test: Unit = | ||
g() // errors | ||
() |