Skip to content
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

Open
rjolly opened this issue Oct 26, 2022 · 10 comments · Fixed by #22220
Open
Assignees
Labels
area:experimental:cc Capture checking related area:repl cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug
Milestone

Comments

@rjolly
Copy link
Contributor

rjolly commented Oct 26, 2022

Compiler version

3.2.2-RC1-bin-SNAPSHOT-git-292e56f

Minimized code

scala> import language.experimental.captureChecking

Output

-- Error: ----------------------------------------------------------------------
1 |import language.experimental.captureChecking
  |                             ^^^^^^^^^^^^^^^
  |                      this language import is only allowed at the toplevel

Expectation

Should work. See f2c1b24

@rjolly rjolly added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 26, 2022
@rjolly rjolly changed the title REPL : pureFunctions and captureChecking fail with language import only allowed at toplevel REPL : pureFunctions and captureChecking fail with "language import only allowed at toplevel" Oct 26, 2022
@dwijnand dwijnand added discussion cc-experiment Intended to be merged with cc-experiment branch on origin area:repl itype:bug and removed itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label discussion labels Oct 26, 2022
@anatoliykmetyuk
Copy link
Contributor

This issue was picked for the Issue Spree No. 23 of 08 November 2022 which takes place in a week from now. @rjolly, @mbovel will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

@dwijnand
Copy link
Member

dwijnand commented Nov 1, 2022

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.

@scala-center-bot
Copy link

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.

@mbovel
Copy link
Member

mbovel commented Jan 17, 2023

#16304 is a work-in-progress PR for this issue, see comments there.

@rjolly
Copy link
Contributor Author

rjolly commented Jan 28, 2025

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.

@Linyxus
Copy link
Contributor

Linyxus commented Jan 28, 2025

I see, I guess we should reopen this issue then?

@Linyxus Linyxus reopened this Jan 28, 2025
@noti0na1
Copy link
Member

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.

@rjolly
Copy link
Contributor Author

rjolly commented Jan 28, 2025

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?

@rjolly
Copy link
Contributor Author

rjolly commented Jan 29, 2025

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.

@rjolly
Copy link
Contributor Author

rjolly commented Jan 29, 2025

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 =>
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental:cc Capture checking related area:repl cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug
Projects
None yet
9 participants