Skip to content

Commit ad92dcd

Browse files
committed
Remove restriction on val _ = .. with top-level experimental imports
1 parent 6ecf7cd commit ad92dcd

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -848,9 +848,8 @@ object Checking {
848848
val sym = tree.symbol
849849
if !sym.isExperimental then
850850
sym.addAnnotation(ExperimentalAnnotation(s"Added by $why", sym.span))
851-
case tree =>
852-
// There is no definition to attach the @experimental annotation
853-
report.error(s"Implementation restriction: top-level `val _ = ...` is not supported with $why.", tree.srcPos)
851+
case _ =>
852+
// statements from a `val _ = ...`
854853
unitExperimentalLanguageImports match
855854
case imp :: _ => markTopLevelDefsAsExperimental(i"top level $imp")
856855
case _ =>

tests/neg/experimental-import-with-top-level-val-underscore.check

-6
This file was deleted.

tests/pos-custom-args/captures/try.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def handle[E <: Exception, R](op: (erased CanThrow[E]) -> R)(handler: E -> R): R
1818
try op(x)
1919
catch case ex: E => handler(ex)
2020

21-
val bar = handle { (erased x) =>
21+
val _ = handle { (erased x) =>
2222
if true then
2323
raise(new Exception)(using x)
2424
22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
import language.experimental.erasedDefinitions
33

4-
val _ = // error
5-
println("Hello, world!")
4+
def test() = ()
5+
6+
val _ =
7+
test()
68
42

0 commit comments

Comments
 (0)