Skip to content

Commit

Permalink
Don't introduce synthetic val res = in REPL completion
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym committed Jun 6, 2021
1 parent fb421a9 commit b93e04e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/repl/scala/tools/nsc/interpreter/IMain.scala
Expand Up @@ -775,7 +775,8 @@ class IMain(val settings: Settings, parentClassLoaderOverride: Option[ClassLoade
}

/** One line of code submitted by the user for interpretation */
class Request(val line: String, origTrees: List[Tree], firstXmlPos: Position = NoPosition, generousImports: Boolean = false, synthetic: Boolean = false) extends ReplRequest {
class Request(val line: String, origTrees: List[Tree], firstXmlPos: Position = NoPosition,
generousImports: Boolean = false, synthetic: Boolean = false, storeResultInVal: Boolean = true) extends ReplRequest {
def defines = defHandlers flatMap (_.definedSymbols)
def definesTermNames: List[String] = defines collect { case s: TermSymbol => s.decodedName.toString }
def imports = importedSymbols
Expand All @@ -801,6 +802,7 @@ class IMain(val settings: Settings, parentClassLoaderOverride: Option[ClassLoade

// Wrap last tree in a valdef to give user a nice handle for it (`resN`)
val trees: List[Tree] = origTrees match {
case xs if !storeResultInVal => xs
case init :+ tree =>
@tailrec def loop(scrut: Tree): Tree = scrut match {
case _: Assign => tree
Expand Down
Expand Up @@ -60,7 +60,7 @@ trait PresentationCompilation { self: IMain =>
}
val importer = global.mkImporter(pc)
//println(s"pc: [[$line1]], <<${trees.size}>>")
val request = new Request(line1, trees map (t => importer.importTree(t)), generousImports = true)
val request = new Request(line1, trees map (t => importer.importTree(t)), generousImports = true, storeResultInVal = false)
val origUnit = request.mkUnit
val unit = new pc.CompilationUnit(origUnit.source)
unit.body = pc.mkImporter(global).importTree(origUnit.body)
Expand Down

0 comments on commit b93e04e

Please sign in to comment.