Skip to content

REPL: Import shadowing issue #5074

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

Open
allanrenucci opened this issue Sep 3, 2018 · 4 comments
Open

REPL: Import shadowing issue #5074

allanrenucci opened this issue Sep 3, 2018 · 4 comments

Comments

@allanrenucci
Copy link
Contributor

scala> object A { def f = 1 }                                                                                                                                                                                   
// defined object A

scala> import A._; def f = 2
def f: Int

scala> f                                                                                                                                                                                                        
val res0: Int = 1 // should be 2
@allanrenucci
Copy link
Contributor Author

This has to do with the way we handle user defined imports and wrap expression in an object:

When we evaluate an expression, we need to imports previously evaluated expressions:
https://github.com/lampepfl/dotty/blob/86c4e72e3a87aae12c57e2c887231b77717438a3/compiler/src/dotty/tools/repl/ReplCompiler.scala#L50-L66

We first import the wrapper object and then the user defined imports in it. So a user defined import might shadow a definition even if the import precedes the definition

@SethTisue
Copy link
Member

this is a regression/change since Scala 2; all Scala 2 versions I tested print 2

(you never know, but sometimes @som-snytt gets interested in these sort of problems...)

@SethTisue
Copy link
Member

SethTisue commented Feb 6, 2025

there is some discussion and analysis on #14951. I wrote:

Dale suggested maybe just forbidding mixing import with other things in a single REPL entry.

It also occurred to both of us that another solution path could be to notice when import is present and automatically split the entry up into multiple entries.

@som-snytt
Copy link
Contributor

Today, it would be more natural to say that import makes symbols available in the current line, and export makes them available to subsequent lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants