-
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: scala.* namespaces shadow other classes #15904
Comments
This duplicates #14781 where
succeeds in REPL but fails in scalac because recent JDK has root package As shown in the Scala 2 ticket (linked from the dotty ticket), Scala 2 REPL also fails (i.e., disagrees with Scala 3 REPL). The "root import" that makes What about top-level packages The current implementation in Scala 2 and 3 really does model a "root package" with an "empty name". However, the lookup of I think the root import For example, a usage A file could https://scala-lang.org/files/archive/spec/2.13/02-identifiers-names-and-scopes.html |
Thanks, yes that's some valid context, and precedence is obviously a very important issue. Note however that my example above isn't really affected by precedence. It defines an Hence, if precedence requires that we first lookup The error message suggests that it actually did look at |
The actual mechanism is that it looks up I had not considered continuing the search for the maximal path. I don't know if that has been discussed in the past and deemed too expensive or confusing. One consequence is that It would solve the annoying problem of common prefixes such as I don't understand your comment about the error message, but I see that it would be more helpful if package references were fully qualified. The compiler works hard to disambiguate other symbols with superscripts, etc.
|
I think in Scala 3 it is level 4. That's where the two versions differ. |
scala> io.foo.Bar.baz
-- [E008] Not Found Error: -------
1 |io.foo.Bar.baz
|^^^^^^
|value foo is not a member of io The user may or may not know that Anyway, that's more of a side note - the main issue remains that the compiler finds that |
I think we should not even consider that approach. That just isn't how scoping in Scala works. If I write |
I'll nag a bit by posting my test, as my previous comment was unclear (to me; quick let me write it down while I remember it): The behavior is different in Scala 3 REPL. The compiler takes rooted The code sample shows that you must use
This ticket shows that in Scala 3 REPL, you must use Both |
However, autocompleting |
Well, that's the design question here, and I'm not sure I agree. I think the behavior of the Scala 2 batch compiler for the last decade-plus is a really strong precedent here and if we wanted to change it — in either Scala 2 or Scala 3 — we need a realllllllly strong argument and we need to be really sure. |
Edit: sorry, I didn't mean to pollute the issue here (which is that REPL's behavior is different from batch). Also, I see I replicated my comment from summertime, because I forgot the details again. Also not relevant here, but worth pointing out, is that taking |
So I suggest that at present, we should simply fix the Scala 3 REPL to match the behavior of the Scala 3 batch compiler. #14021 has some good relevant history/code/tests. |
Agree. |
I think we're all on the same boat when it comes to 'where we want to sail', see #15904 (comment) That's a great first step I guess... |
🥳 🍰 thanks everyone! |
Compiler version
Scala 3.1.3
Scala 3.2.0-RC4
Minimized code
Expectation
The repl should resolve
io.foo
without the_root_
prefix.Initial analysis
scala.io
shadowsio.foo
. Same goes for allscala.*
packages.The above works fine in ammonite's scala3 repl as well as the default scala2 repl.
The text was updated successfully, but these errors were encountered: