Skip to content

Commit

Permalink
SI-5943 toolboxes now autoimport Predef and scala
Browse files Browse the repository at this point in the history
Previously tb.typeCheck used default typer, which builds upon NoContext.
Changing the context to analyzer.rootContext(NoCompilationUnit, EmptyTree)
fixed the missing imports problem.

Unfortunately this doesn't help in cases like "math.sqrt(4.0)" because of
https://issues.scala-lang.org/browse/SI-6393. But anyways I'm adding
this test case to pending.
  • Loading branch information
xeno-by committed Sep 20, 2012
1 parent 66603a2 commit 440d28d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compiler/scala/reflect/reify/package.scala
Expand Up @@ -73,7 +73,7 @@ package object reify {
def reifyEnclosingRuntimeClass(global: Global)(typer0: global.analyzer.Typer): global.Tree = {
import global._
import definitions._
def isThisInScope = typer0.context.enclosingContextChain exists (_.tree.isInstanceOf[Template])
def isThisInScope = typer0.context.enclosingContextChain exists (_.tree.isInstanceOf[ImplDef])
if (isThisInScope) {
val enclosingClasses = typer0.context.enclosingContextChain map (_.tree) collect { case classDef: ClassDef => classDef }
val classInScope = enclosingClasses.headOption getOrElse EmptyTree
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/reflect/ToolBoxFactory.scala
Expand Up @@ -111,7 +111,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
val ownerClass = rootMirror.EmptyPackageClass.newClassSymbol(newTypeName("<expression-owner>"))
build.setTypeSignature(ownerClass, ClassInfoType(List(ObjectClass.tpe), newScope, ownerClass))
val owner = ownerClass.newLocalDummy(expr.pos)
var currentTyper = typer.atOwner(expr, owner)
var currentTyper = analyzer.newTyper(analyzer.rootContext(NoCompilationUnit, EmptyTree).make(expr, owner))
val wrapper1 = if (!withImplicitViewsDisabled) (currentTyper.context.withImplicitsEnabled[Tree] _) else (currentTyper.context.withImplicitsDisabled[Tree] _)
val wrapper2 = if (!withMacrosDisabled) (currentTyper.context.withMacrosEnabled[Tree] _) else (currentTyper.context.withMacrosDisabled[Tree] _)
def wrapper (tree: => Tree) = wrapper1(wrapper2(tree))
Expand Down
1 change: 1 addition & 0 deletions test/files/run/t5943a1.check
@@ -0,0 +1 @@
scala.this.Predef.intWrapper(1).to(3).map[Int, scala.collection.immutable.IndexedSeq[Int]](((x$1: Int) => x$1.+(1)))(immutable.this.IndexedSeq.canBuildFrom[Int])
9 changes: 9 additions & 0 deletions test/files/run/t5943a1.scala
@@ -0,0 +1,9 @@
import scala.reflect.runtime.universe._
import scala.reflect.runtime.{currentMirror => cm}
import scala.tools.reflect.ToolBox

object Test extends App {
val tb = cm.mkToolBox()
val expr = tb.parse("1 to 3 map (_+1)")
println(tb.typeCheck(expr))
}
1 change: 1 addition & 0 deletions test/files/run/t5943a2.check
@@ -0,0 +1 @@
Vector(2, 3, 4)
9 changes: 9 additions & 0 deletions test/files/run/t5943a2.scala
@@ -0,0 +1,9 @@
import scala.reflect.runtime.universe._
import scala.reflect.runtime.{currentMirror => cm}
import scala.tools.reflect.ToolBox

object Test extends App {
val tb = cm.mkToolBox()
val expr = tb.parse("1 to 3 map (_+1)")
println(tb.eval(expr))
}
10 changes: 10 additions & 0 deletions test/pending/run/t5943b1.scala
@@ -0,0 +1,10 @@
import scala.reflect.runtime.universe._
import scala.reflect.runtime.{currentMirror => cm}
import scala.tools.reflect.ToolBox

// pending until https://issues.scala-lang.org/browse/SI-6393 is fixed
object Test extends App {
val tb = cm.mkToolBox()
val expr = tb.parse("math.sqrt(4.0)")
println(tb.typeCheck(expr))
}
10 changes: 10 additions & 0 deletions test/pending/run/t5943b2.scala
@@ -0,0 +1,10 @@
import scala.reflect.runtime.universe._
import scala.reflect.runtime.{currentMirror => cm}
import scala.tools.reflect.ToolBox

// pending until https://issues.scala-lang.org/browse/SI-6393 is fixed
object Test extends App {
val tb = cm.mkToolBox()
val expr = tb.parse("math.sqrt(4.0)")
println(tb.eval(expr))
}

0 comments on commit 440d28d

Please sign in to comment.