File tree 2 files changed +27
-1
lines changed
src/dotty/tools/dotc/parsing
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -3706,7 +3706,15 @@ object Parsers {
3706
3706
in.languageImportContext = in.languageImportContext.importContext(imp, NoSymbol )
3707
3707
for case ImportSelector (id @ Ident (imported), EmptyTree , _) <- selectors do
3708
3708
if Feature .handleGlobalLanguageImport(prefix, imported) && ! outermost then
3709
- syntaxError(em " this language import is only allowed at the toplevel " , id.span)
3709
+ val desc =
3710
+ if ctx.mode.is(Mode .Interactive ) then
3711
+ " not allowed in the REPL"
3712
+ else " only allowed at the toplevel"
3713
+ val hint =
3714
+ if ctx.mode.is(Mode .Interactive ) then
3715
+ f " \n To use this language feature, include the flag `-language: $prefix. $imported` when starting the REPL "
3716
+ else " "
3717
+ syntaxError(em " this language import is $desc$hint" , id.span)
3710
3718
if allSourceVersionNames.contains(imported) && prefix.isEmpty then
3711
3719
if ! outermost then
3712
3720
syntaxError(em " source version import is only allowed at the toplevel " , id.span)
Original file line number Diff line number Diff line change @@ -493,6 +493,24 @@ class ReplCompilerTests extends ReplTest:
493
493
assertTrue(all.head.startsWith(" -- [E103] Syntax Error" ))
494
494
assertTrue(all.exists(_.trim().startsWith(" | Illegal start of statement: this modifier is not allowed here" )))
495
495
496
+ @ Test def `i16250a` : Unit = initially :
497
+ val hints = List (
498
+ " this language import is not allowed in the REPL" ,
499
+ " To use this language feature, include the flag `-language:experimental.captureChecking` when starting the REPL"
500
+ )
501
+ run(" import language.experimental.captureChecking" )
502
+ val all = lines()
503
+ assertTrue(hints.forall(hint => all.exists(_.contains(hint))))
504
+
505
+ @ Test def `i16250b` : Unit = initially :
506
+ val hints = List (
507
+ " this language import is not allowed in the REPL" ,
508
+ " To use this language feature, include the flag `-language:experimental.pureFunctions` when starting the REPL"
509
+ )
510
+ run(" import language.experimental.pureFunctions" )
511
+ val all = lines()
512
+ assertTrue(hints.forall(hint => all.exists(_.contains(hint))))
513
+
496
514
object ReplCompilerTests :
497
515
498
516
private val pattern = Pattern .compile(" \\ r[\\ n]?|\\ n" );
You can’t perform that action at this time.
0 commit comments