Skip to content

Fix #11146: Don't re-add root imports to context in REPLFrontEnd #12303

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

Merged
merged 1 commit into from
May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/repl/ReplFrontEnd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package repl
import dotc.typer.FrontEnd
import dotc.CompilationUnit
import dotc.core.Contexts._
import dotc.typer.ImportInfo.withRootImports

/** A customized `FrontEnd` for the REPL
*
Expand All @@ -19,7 +18,7 @@ private[repl] class REPLFrontEnd extends FrontEnd {
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = {
assert(units.size == 1) // REPl runs one compilation unit at a time
val unit = units.head
val unitContext = ctx.fresh.setCompilationUnit(unit).withRootImports
val unitContext = ctx.fresh.setCompilationUnit(unit)
enterSyms(using unitContext)
typeCheck(using unitContext)
List(unit)
Expand Down
25 changes: 25 additions & 0 deletions compiler/test-resources/repl/i11146
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
scala> class Appendable { def foo = println("Appendable.foo") }
// defined class Appendable

scala> (new Appendable).foo
Appendable.foo

scala> def assert(x: Boolean) = println(if x then "not asserted" else "asserted")
def assert(x: Boolean): Unit

scala> assert(false)
asserted

scala> class Option; object Option { val baz = 42 }
// defined class Option
// defined object Option

scala> Option.baz
val res0: Int = 42

scala> object fs2 { class Stream[T] { override def toString = "fs2.Stream(..)" }; object Stream { def apply[T](x: T) = new Stream[T] }}
// defined object fs2

scala> import fs2.Stream
scala> Stream(1)
val res1: fs2.Stream[Int] = fs2.Stream(..)