8000 Added test for -Yliteral-types combined with macro and toolbox eval · scala/scala@07341a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 07341a0

Browse files
committed
Added test for -Yliteral-types combined with macro and toolbox eval
1 parent 4c2ea46 commit 07341a0

File tree

7 files changed

+31
-2
lines changed

7 files changed

+31
-2
lines changed

src/compiler/scala/reflect/macros/contexts/Evals.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ trait Evals {
88
self: Context =>
99

1010
private lazy val evalMirror = ru.runtimeMirror(universe.analyzer.defaultMacroClassloader)
11-
private lazy val evalToolBox = evalMirror.mkToolBox()
11+
private lazy val evalToolBox = evalMirror.mkToolBox(options = if(global.settings.YliteralTypes) "-Yliteral-types" else "")
1212
private lazy val evalImporter = ru.internal.createImporter(universe).asInstanceOf[ru.Importer { val from: universe.type }]
1313

1414
def eval[T](expr: Expr[T]): T = {
@@ -20,4 +20,4 @@ trait Evals {
2020
evalToolBox.eval(imported).asInstanceOf[T]
2121
}
2222
}
23-
}
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Yliteral-types
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.language.experimental.macros
2+
import scala.reflect.macros.blackbox.Context
3+
4+
object Macros {
5+
def impl(c: Context): c.Expr[Any] = {
6+
import c.universe._;
7+
8+
val res0 = c.eval(c.Expr[Any](q"implicitly[ValueOf[1]]"))
9+
val res = res0.asInstanceOf[ValueOf[1]].value
10+
11+
c.Expr[Any](q"$res")
12+
}
13+
14+
def eval: Any = macro impl
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Yliteral-types
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test extends App {
2+
val res = Macros.eval
3+
assert(res == 1)
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Yliteral-types
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.tools.reflect.ToolBox
2+
import scala.reflect.runtime.{ universe => ru }
3+
4+
object Test extends App {
5+
val tb = scala.reflect.runtime.currentMirror.mkToolBox(options = "-Yliteral-types")
6+
tb.eval(ru.reify(implicitly[ValueOf[1]]).tree)
7+
}

0 commit comments

Comments
 (0)
0