summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Macros.scala8
-rw-r--r--src/compiler/scala/tools/reflect/FastTrack.scala24
-rw-r--r--test/files/neg/compile-time-only-b.check8
-rw-r--r--test/files/neg/macro-reify-splice-splice.check7
-rw-r--r--test/files/neg/macro-reify-splice-splice.flags (renamed from test/files/run/macro-reify-splice-splice.flags)0
-rw-r--r--test/files/neg/macro-reify-splice-splice/Macros_1.scala (renamed from test/files/run/macro-reify-splice-splice/Macros_1.scala)0
-rw-r--r--test/files/neg/macro-reify-splice-splice/Test_2.scala (renamed from test/files/run/macro-reify-splice-splice/Test_2.scala)0
-rw-r--r--test/files/neg/t6539.check8
-rw-r--r--test/files/run/macro-reify-splice-splice.check1
-rw-r--r--test/files/run/macro-typecheck-macrosdisabled.check4
-rw-r--r--test/files/run/macro-typecheck-macrosdisabled2.check4
-rw-r--r--test/files/run/t8091.check1
-rw-r--r--test/files/run/t8091.scala4
-rw-r--r--test/files/run/toolbox_typecheck_macrosdisabled.check4
-rw-r--r--test/files/run/toolbox_typecheck_macrosdisabled2.check4
15 files changed, 53 insertions, 24 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
index 1deb74640c..0d46a96b81 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
@@ -260,7 +260,11 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers {
}
def isBlackbox(expandee: Tree): Boolean = isBlackbox(dissectApplied(expandee).core.symbol)
- def isBlackbox(macroDef: Symbol): Boolean = loadMacroImplBinding(macroDef).map(_.isBlackbox).getOrElse(false)
+ def isBlackbox(macroDef: Symbol): Boolean = {
+ val fastTrackBoxity = fastTrack.get(macroDef).map(_.isBlackbox)
+ val bindingBoxity = loadMacroImplBinding(macroDef).map(_.isBlackbox)
+ fastTrackBoxity orElse bindingBoxity getOrElse false
+ }
def computeMacroDefTypeFromMacroImplRef(macroDdef: DefDef, macroImplRef: Tree): Type = {
macroImplRef match {
@@ -634,7 +638,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers {
}
if (isBlackbox(expandee)) {
- val expanded1 = atPos(enclosingMacroPosition.focus)(Typed(expanded0, TypeTree(innerPt)))
+ val expanded1 = atPos(enclosingMacroPosition.makeTransparent)(Typed(expanded0, TypeTree(innerPt)))
typecheck("blackbox typecheck", expanded1, outerPt)
} else {
val expanded1 = expanded0
diff --git a/src/compiler/scala/tools/reflect/FastTrack.scala b/src/compiler/scala/tools/reflect/FastTrack.scala
index dd92e14602..bb0bbd79a3 100644
--- a/src/compiler/scala/tools/reflect/FastTrack.scala
+++ b/src/compiler/scala/tools/reflect/FastTrack.scala
@@ -24,10 +24,12 @@ trait FastTrack {
new { val c: c0.type = c0 } with MacroImplementations
private implicit def context2quasiquote(c0: MacroContext): QuasiquoteImpls { val c: c0.type } =
new { val c: c0.type = c0 } with QuasiquoteImpls
- private def make(sym: Symbol)(pf: PartialFunction[Applied, MacroContext => Tree]) =
- sym -> new FastTrackEntry(pf)
+ private def makeBlackbox(sym: Symbol)(pf: PartialFunction[Applied, MacroContext => Tree]) =
+ sym -> new FastTrackEntry(pf, isBlackbox = true)
+ private def makeWhitebox(sym: Symbol)(pf: PartialFunction[Applied, MacroContext => Tree]) =
+ sym -> new FastTrackEntry(pf, isBlackbox = false)
- final class FastTrackEntry(pf: PartialFunction[Applied, MacroContext => Tree]) extends (MacroArgs => Any) {
+ final class FastTrackEntry(pf: PartialFunction[Applied, MacroContext => Tree], val isBlackbox: Boolean) extends (MacroArgs => Any) {
def validate(tree: Tree) = pf isDefinedAt Applied(tree)
def apply(margs: MacroArgs): margs.c.Expr[Nothing] = {
val MacroArgs(c, _) = margs
@@ -42,14 +44,14 @@ trait FastTrack {
val runDefinitions = currentRun.runDefinitions
import runDefinitions._
Map[Symbol, FastTrackEntry](
- make( materializeClassTag) { case Applied(_, ttag :: Nil, _) => _.materializeClassTag(ttag.tpe) },
- make( materializeWeakTypeTag) { case Applied(_, ttag :: Nil, (u :: _) :: _) => _.materializeTypeTag(u, EmptyTree, ttag.tpe, concrete = false) },
- make( materializeTypeTag) { case Applied(_, ttag :: Nil, (u :: _) :: _) => _.materializeTypeTag(u, EmptyTree, ttag.tpe, concrete = true) },
- make( ApiUniverseReify) { case Applied(_, ttag :: Nil, (expr :: _) :: _) => c => c.materializeExpr(c.prefix.tree, EmptyTree, expr) },
- make( StringContext_f) { case Applied(Select(Apply(_, ps), _), _, args) => c => c.macro_StringInterpolation_f(ps, args.flatten, c.expandee.pos) },
- make(ReflectRuntimeCurrentMirror) { case _ => c => currentMirror(c).tree },
- make( QuasiquoteClass_api_apply) { case _ => _.expandQuasiquote },
- make(QuasiquoteClass_api_unapply) { case _ => _.expandQuasiquote }
+ makeBlackbox( materializeClassTag) { case Applied(_, ttag :: Nil, _) => _.materializeClassTag(ttag.tpe) },
+ makeBlackbox( materializeWeakTypeTag) { case Applied(_, ttag :: Nil, (u :: _) :: _) => _.materializeTypeTag(u, EmptyTree, ttag.tpe, concrete = false) },
+ makeBlackbox( materializeTypeTag) { case Applied(_, ttag :: Nil, (u :: _) :: _) => _.materializeTypeTag(u, EmptyTree, ttag.tpe, concrete = true) },
+ makeBlackbox( ApiUniverseReify) { case Applied(_, ttag :: Nil, (expr :: _) :: _) => c => c.materializeExpr(c.prefix.tree, EmptyTree, expr) },
+ makeBlackbox( StringContext_f) { case Applied(Select(Apply(_, ps), _), _, args) => c => c.macro_StringInterpolation_f(ps, args.flatten, c.expandee.pos) },
+ makeBlackbox(ReflectRuntimeCurrentMirror) { case _ => c => currentMirror(c).tree },
+ makeWhitebox( QuasiquoteClass_api_apply) { case _ => _.expandQuasiquote },
+ makeWhitebox(QuasiquoteClass_api_unapply) { case _ => _.expandQuasiquote }
)
}
}
diff --git a/test/files/neg/compile-time-only-b.check b/test/files/neg/compile-time-only-b.check
index 8292a0ddeb..50cdf57fb5 100644
--- a/test/files/neg/compile-time-only-b.check
+++ b/test/files/neg/compile-time-only-b.check
@@ -1,7 +1,13 @@
+compile-time-only-b.scala:9: error: splice must be enclosed within a reify {} block
+ val ignored1 = expr.splice
+ ^
+compile-time-only-b.scala:10: error: cannot use value except for signatures of macro implementations
+ val ignored2 = expr.value
+ ^
compile-time-only-b.scala:13: error: splice must be enclosed within a reify {} block
val ignored3 = reify(fortyTwo).splice
^
compile-time-only-b.scala:14: error: cannot use value except for signatures of macro implementations
val ignored4 = reify(fortyTwo).value
^
-two errors found
+four errors found
diff --git a/test/files/neg/macro-reify-splice-splice.check b/test/files/neg/macro-reify-splice-splice.check
new file mode 100644
index 0000000000..bd1ea7acee
--- /dev/null
+++ b/test/files/neg/macro-reify-splice-splice.check
@@ -0,0 +1,7 @@
+Macros_1.scala:8: error: the splice cannot be resolved statically, which means there is a cross-stage evaluation involved.
+cross-stage evaluations need to be invoked explicitly, so we're showing you this error.
+if you're sure this is not an oversight, add scala-compiler.jar to the classpath,
+import `scala.tools.reflect.Eval` and call `<your expr>.eval` instead.
+ { c.universe.reify(c.universe.reify("hello world")) }.splice.splice
+ ^
+one error found
diff --git a/test/files/run/macro-reify-splice-splice.flags b/test/files/neg/macro-reify-splice-splice.flags
index cd66464f2f..cd66464f2f 100644
--- a/test/files/run/macro-reify-splice-splice.flags
+++ b/test/files/neg/macro-reify-splice-splice.flags
diff --git a/test/files/run/macro-reify-splice-splice/Macros_1.scala b/test/files/neg/macro-reify-splice-splice/Macros_1.scala
index 691f22ad07..691f22ad07 100644
--- a/test/files/run/macro-reify-splice-splice/Macros_1.scala
+++ b/test/files/neg/macro-reify-splice-splice/Macros_1.scala
diff --git a/test/files/run/macro-reify-splice-splice/Test_2.scala b/test/files/neg/macro-reify-splice-splice/Test_2.scala
index f697da6020..f697da6020 100644
--- a/test/files/run/macro-reify-splice-splice/Test_2.scala
+++ b/test/files/neg/macro-reify-splice-splice/Test_2.scala
diff --git a/test/files/neg/t6539.check b/test/files/neg/t6539.check
index b647636338..8c94a8ad4c 100644
--- a/test/files/neg/t6539.check
+++ b/test/files/neg/t6539.check
@@ -7,4 +7,10 @@ Test_2.scala:3: error: cto may only be used as an argument to m
Test_2.scala:5: error: cto may only be used as an argument to m
M.cto // error
^
-three errors found
+Test_2.scala:9: error: splice must be enclosed within a reify {} block
+ val splice = expr.splice
+ ^
+Test_2.scala:10: error: cannot use value except for signatures of macro implementations
+ val value = expr.value
+ ^
+5 errors found
diff --git a/test/files/run/macro-reify-splice-splice.check b/test/files/run/macro-reify-splice-splice.check
deleted file mode 100644
index 3b18e512db..0000000000
--- a/test/files/run/macro-reify-splice-splice.check
+++ /dev/null
@@ -1 +0,0 @@
-hello world
diff --git a/test/files/run/macro-typecheck-macrosdisabled.check b/test/files/run/macro-typecheck-macrosdisabled.check
index e0e880ab66..0579a4f4c8 100644
--- a/test/files/run/macro-typecheck-macrosdisabled.check
+++ b/test/files/run/macro-typecheck-macrosdisabled.check
@@ -1,4 +1,4 @@
-{
+({
val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe;
val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(this.getClass().getClassLoader());
$u.Expr.apply[Int(2)]($m, {
@@ -28,5 +28,5 @@
};
new $typecreator2()
}))
-}
+}: reflect.runtime.universe.Expr[Int])
ru.reify[Int](2)
diff --git a/test/files/run/macro-typecheck-macrosdisabled2.check b/test/files/run/macro-typecheck-macrosdisabled2.check
index 347dfec1dc..c6e1c08d5d 100644
--- a/test/files/run/macro-typecheck-macrosdisabled2.check
+++ b/test/files/run/macro-typecheck-macrosdisabled2.check
@@ -1,4 +1,4 @@
-{
+({
val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe;
val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(this.getClass().getClassLoader());
$u.Expr.apply[Array[Int]]($m, {
@@ -28,5 +28,5 @@
};
new $typecreator2()
}))
-}
+}: reflect.runtime.universe.Expr[Array[Int]])
ru.reify[Array[Int]](scala.Array.apply(2))
diff --git a/test/files/run/t8091.check b/test/files/run/t8091.check
new file mode 100644
index 0000000000..4c4e91774f
--- /dev/null
+++ b/test/files/run/t8091.check
@@ -0,0 +1 @@
+b&#x00f6;rk b&#x00f6;rk
diff --git a/test/files/run/t8091.scala b/test/files/run/t8091.scala
new file mode 100644
index 0000000000..cd412d4c2a
--- /dev/null
+++ b/test/files/run/t8091.scala
@@ -0,0 +1,4 @@
+object Test extends App {
+ val result = "börk börk" flatMap (ch ⇒ if (ch > 127) f"&#x${ch}%04x;" else "" + ch)
+ println(result)
+} \ No newline at end of file
diff --git a/test/files/run/toolbox_typecheck_macrosdisabled.check b/test/files/run/toolbox_typecheck_macrosdisabled.check
index 3de296f1ad..d9e79cdd19 100644
--- a/test/files/run/toolbox_typecheck_macrosdisabled.check
+++ b/test/files/run/toolbox_typecheck_macrosdisabled.check
@@ -1,4 +1,4 @@
-{
+({
val $u: ru.type = ru;
val $m: $u.Mirror = ru.runtimeMirror({
final class $anon extends scala.AnyRef {
@@ -37,5 +37,5 @@
};
new $typecreator2()
}))
-}
+}: ru.Expr[Int])
ru.reify[Int](2)
diff --git a/test/files/run/toolbox_typecheck_macrosdisabled2.check b/test/files/run/toolbox_typecheck_macrosdisabled2.check
index 9810946024..8e554a6c8f 100644
--- a/test/files/run/toolbox_typecheck_macrosdisabled2.check
+++ b/test/files/run/toolbox_typecheck_macrosdisabled2.check
@@ -1,4 +1,4 @@
-{
+({
val $u: ru.type = ru;
val $m: $u.Mirror = ru.runtimeMirror({
final class $anon extends scala.AnyRef {
@@ -37,5 +37,5 @@
};
new $typecreator2()
}))
-}
+}: ru.Expr[Array[Int]])
ru.reify[Array[Int]](scala.Array.apply(2))