Skip to content

Commit 9b225c1

Browse files
committed
Don't re-add root imports to context in REPLFrontEnd
The root context for REPL compiler runs is initialized by ReplCompiler#newRun, which contains special handling to: 1. first add the default root imports (java.lang._, scala._, Predef._) 2. then import each previous REPL wrapper in order (incl. its imports) The result is the innermost context imports the most recent REPL wrapper and the (nearly) outermost contexts contain the default imports. Before this commit, the default root imports were also being added to the (innermost) context in REPLFrontEnd#runOn, resulting in REPL definitions being shadowed by those in java.lang._, scala._ and Predef._
1 parent affe8d0 commit 9b225c1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

compiler/src/dotty/tools/repl/ReplFrontEnd.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package repl
44
import dotc.typer.FrontEnd
55
import dotc.CompilationUnit
66
import dotc.core.Contexts._
7-
import dotc.typer.ImportInfo.withRootImports
87

98
/** A customized `FrontEnd` for the REPL
109
*
@@ -19,7 +18,7 @@ private[repl] class REPLFrontEnd extends FrontEnd {
1918
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = {
2019
assert(units.size == 1) // REPl runs one compilation unit at a time
2120
val unit = units.head
22-
val unitContext = ctx.fresh.setCompilationUnit(unit).withRootImports
21+
val unitContext = ctx.fresh.setCompilationUnit(unit)
2322
enterSyms(using unitContext)
2423
typeCheck(using unitContext)
2524
List(unit)

compiler/test-resources/repl/i11146

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
scala> class Appendable { def foo = println("Appendable.foo") }
2+
// defined class Appendable
3+
4+
scala> (new Appendable).foo
5+
Appendable.foo
6+
7+
scala> def assert(x: Boolean) = println(if x then "not asserted" else "asserted")
8+
def assert(x: Boolean): Unit
9+
10+
scala> assert(false)
11+
asserted
12+
13+
scala> class Option; object Option { val baz = 42 }
14+
// defined class Option
15+
// defined object Option
16+
17+
scala> Option.baz
18+
val res0: Int = 42
19+
20+
scala> object fs2 { class Stream[T] { override def toString = "fs2.Stream(..)" }; object Stream { def apply[T](x: T) = new Stream[T] }}
21+
// defined object fs2
22+
23+
scala> import fs2.Stream
24+
scala> Stream(1)
25+
val res1: fs2.Stream[Int] = fs2.Stream(..)

0 commit comments

Comments
 (0)