File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -3706,7 +3706,15 @@ object Parsers {
37063706 in.languageImportContext = in.languageImportContext.importContext(imp, NoSymbol )
37073707 for case ImportSelector (id @ Ident (imported), EmptyTree , _) <- selectors do
37083708 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)
37103718 if allSourceVersionNames.contains(imported) && prefix.isEmpty then
37113719 if ! outermost then
37123720 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:
493493 assertTrue(all.head.startsWith(" -- [E103] Syntax Error" ))
494494 assertTrue(all.exists(_.trim().startsWith(" | Illegal start of statement: this modifier is not allowed here" )))
495495
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+
496514object ReplCompilerTests :
497515
498516 private val pattern = Pattern .compile(" \\ r[\\ n]?|\\ n" );
You can’t perform that action at this time.
0 commit comments