-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REPL : pureFunctions and captureChecking fail with "language import only allowed at toplevel" #16250
Comments
Working on imports and the REPL is hard. I encountered this reality while working on PR #14021 and there's related history that touches on things like withRootImports and the CollectTopLevelImports phase. |
This issue was picked for the Issue Spree No. 25 of 24 January 2023 which takes place in a week from now. @rjolly, @TheElectronWill will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here. |
#16304 is a work-in-progress PR for this issue, see comments there. |
This is not right. The intent was instead to fix what the interpreter thinks is the toplevel. Using the command line option is not always possible, for instance with the JSR 223 scripting engine. |
I see, I guess we should reopen this issue then? |
The discussion we had was that capture checking import should not be allowed in REPL, to avoid any wired interaction between CCed symbols and non-CC symbols. |
Yes, it is still important to restrict it to the toplevel - for any definition of toplevel, namely one that matches what we get with a command line option. Does that make sense? |
I think the problem is that each interpreter input line is embedded in an object before compilation: object Line {
import language.experimental.captureChecking
// ^^^^^^^^^^^^^^^
// this language import is only allowed at the toplevel
class Test
} This is so that its terms can be reused later, through an import that is automatically added in the header of subsequent input line/objects. Maybe we could use instead some kind of package or package object? There might be tips in this discussion. |
Specifically, running the repl with -Xprint:typer and a language import that does not fail, we have: package <empty> {
final lazy module val rs$line$1: rs$line$1 = new rs$line$1()
final module class rs$line$1() extends Object() { this: rs$line$1.type =>
import language.experimental.genericNumberLiterals
}
} Maybe we could, for a given input line : gather every imports and move them to outer scope: import language.experimental.captureChecking
package <empty> {
final lazy module val rs$line$1: rs$line$1 = new rs$line$1()
final module class rs$line$1() extends Object() { this: rs$line$1.type =>
}
} |
Compiler version
3.2.2-RC1-bin-SNAPSHOT-git-292e56f
Minimized code
Output
Expectation
Should work. See f2c1b24
The text was updated successfully, but these errors were encountered: