Skip to content

Commit b21523b

Browse files
committed
Remove restriction on val _ = .. with top-level experimental imports
1 parent 1ebae87 commit b21523b

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,8 @@ object Checking {
843843
val sym = tree.symbol
844844
if !sym.isExperimental then
845845
sym.addAnnotation(ExperimentalAnnotation(s"Added by $why", sym.span))
846-
case tree =>
847-
// There is no definition to attach the @experimental annotation
848-
report.error(s"Implementation restriction: top-level `val _ = ...` is not supported with $why.", tree.srcPos)
846+
case _ =>
847+
// statements from a `val _ = ...`
849848
unitExperimentalLanguageImports match
850849
case imp :: _ => markTopLevelDefsAsExperimental(i"top level $imp")
851850
case _ =>

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

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

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

Lines changed: 1 addition & 1 deletion
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)