Skip to content

Member defined in REPL should shadow previously imported member #4230

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

Closed
Blaisorblade opened this issue Apr 2, 2018 · 1 comment
Closed

Comments

@Blaisorblade
Copy link
Contributor

Blaisorblade commented Apr 2, 2018

Below an (un)reproducible transcript of the REPL not handling shadowing correctly. After both importing and defining f, only the imported one is in scope.

> repl
[...]
scala> object A { def f = 1 }
// defined object A
scala> import A._
scala> def f = "hi"
def f: String
scala> f
val res0: Int = 1
@smarter smarter changed the title Shadowing in REPL Member defined in REPL should shadow previously imported member Apr 2, 2018
@allanrenucci
Copy link
Contributor

This has to do with the way we handle imports. When compiling an expression, we first import the previous wrapper objects and then the user defined imports. So currently, a definition imported with an import will always take precedence over one defined in a previous run

@allanrenucci allanrenucci self-assigned this Aug 4, 2018
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Aug 8, 2018
We used to collect imports from the parsed tree and insert them as
parsed trees at the top of the REPL wrapper object. This caused members
shadowing issues.

We now introduce a phase in the REPL compiler that collects imports
after type checking and store them as typed tree. We can then create a
context with its imports set in the correct order and use it to compile
future expressions.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Aug 8, 2018
We used to collect imports from the parsed tree and insert them as
parsed trees at the top of the REPL wrapper object. This caused members
shadowing issues.

We now introduce a phase in the REPL compiler that collects imports
after type checking and store them as typed tree. We can then create a
context with its imports set in the correct order and use it to compile
future expressions.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Aug 21, 2018
We used to collect user defined imports from the parsed tree and
insert them as untyped trees at the top of the REPL wrapper object.
This caused members shadowing issues.

We now introduce a phase in the REPL compiler that collects imports
after type checking and store them as typed tree. We can then create a
context with its imports set in the correct order and use it to compile
future expressions.
nicolasstucki pushed a commit to dotty-staging/dotty that referenced this issue Aug 22, 2018
We used to collect imports from the parsed tree and insert them as
parsed trees at the top of the REPL wrapper object. This caused members
shadowing issues.

We now introduce a phase in the REPL compiler that collects imports
after type checking and store them as typed tree. We can then create a
context with its imports set in the correct order and use it to compile
future expressions.
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 22, 2018
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Aug 22, 2018
We used to collect user defined imports from the parsed tree and
insert them as untyped trees at the top of the REPL wrapper object.
This caused members shadowing issues.

We now introduce a phase in the REPL compiler that collects imports
after type checking and store them as typed tree. We can then create a
context with its imports set in the correct order and use it to compile
future expressions.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Aug 22, 2018
We used to collect imports from the parsed tree and insert them as
parsed trees at the top of the REPL wrapper object. This caused members
shadowing issues.

We now introduce a phase in the REPL compiler that collects imports
after type checking and store them as typed tree. We can then create a
context with its imports set in the correct order and use it to compile
future expressions.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Aug 28, 2018
We used to collect user defined imports from the parsed tree and
insert them as untyped trees at the top of the REPL wrapper object.
This caused members shadowing issues.

We now introduce a phase in the REPL compiler that collects imports
after type checking and store them as typed tree. We can then create a
context with its imports set in the correct order and use it to compile
future expressions.

This also fixes scala#4978 by having user defined import in the run context.
Auto-completions somehow ignored them when they were part of the
untyped tree.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Aug 28, 2018
We used to collect user defined imports from the parsed tree and
insert them as untyped trees at the top of the REPL wrapper object.
This caused members shadowing issues.

We now introduce a phase in the REPL compiler that collects imports
after type checking and store them as typed tree. We can then create a
context with its imports set in the correct order and use it to compile
future expressions.

This also fixes scala#4978 by having user defined import in the run context.
Auto-completions somehow ignored them when they were part of the
untyped tree.
allanrenucci added a commit that referenced this issue Sep 3, 2018
Fix #4230: Handle import in the REPL correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants