From ce37ae45e22463a3f1a2d659d6699f2977b26c6b Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 2 Oct 2013 16:47:11 +0200 Subject: blackbox and whitebox macros This is the first commit in the series. This commit only: 1) Splits Context into BlackboxContext and WhiteboxContext 2) Splits Macro into BlackboxMacro and WhiteboxMacro 3) Introduces the isBundle property in the macro impl binding Here we just teach the compiler that macros can now be blackbox and whitebox, without actually imposing any restrictions on blackbox macros. These restrictions will come in subsequent commits. For description and documentation of the blackbox/whitebox separation see the official macro guide at the scaladoc website: http://docs.scala-lang.org/overviews/macros/blackbox-whitebox.html Some infrastructure work to make evolving macros easier: compile partest-extras with quick so they can use latest library/reflect/... --- test/files/neg/macro-abort/Macros_1.scala | 4 +- .../macro-basic-mamdmi/Impls_Macros_Test_1.scala | 2 +- test/files/neg/macro-bundle-abstract.check | 4 +- test/files/neg/macro-bundle-abstract.scala | 5 +- test/files/neg/macro-bundle-class.check | 2 +- test/files/neg/macro-bundle-class.scala | 6 +- test/files/neg/macro-bundle-mixbox.check | 4 ++ test/files/neg/macro-bundle-mixbox.scala | 10 ++++ test/files/neg/macro-bundle-object.check | 6 +- test/files/neg/macro-bundle-object.scala | 7 +-- test/files/neg/macro-bundle-polymorphic.check | 6 +- test/files/neg/macro-bundle-polymorphic.scala | 5 +- test/files/neg/macro-bundle-trait.check | 2 +- test/files/neg/macro-bundle-trait.scala | 8 +-- test/files/neg/macro-cyclic/Impls_Macros_1.scala | 4 +- .../Impls_Macros_1.scala | 4 +- test/files/neg/macro-exception/Macros_1.scala | 4 +- .../Impls_Macros_1.scala | 4 +- test/files/neg/macro-invalidimpl.check | 20 +++---- test/files/neg/macro-invalidimpl/Impls_1.scala | 20 +++---- .../neg/macro-invalidimpl/Macros_Test_2.scala | 4 +- test/files/neg/macro-invalidret.check | 12 ++-- test/files/neg/macro-invalidret/Impls_1.scala | 6 +- test/files/neg/macro-invalidshape/Impls_1.scala | 2 +- .../neg/macro-invalidshape/Macros_Test_2.scala | 2 +- .../neg/macro-invalidsig-params-badtype.check | 6 +- .../Impls_Macros_1.scala | 2 +- test/files/neg/macro-invalidsig.check | 70 +++++++++++----------- test/files/neg/macro-invalidsig/Impls_1.scala | 30 +++++----- .../neg/macro-invalidusage-badargs/Impls_1.scala | 2 +- .../neg/macro-invalidusage-badbounds/Impls_1.scala | 2 +- .../neg/macro-invalidusage-badtargs/Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../neg/macro-invalidusage-presuper/Impls_1.scala | 4 +- test/files/neg/macro-noexpand/Impls_1.scala | 2 +- test/files/neg/macro-nontypeablebody/Impls_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../Impls_Macros_1.scala | 4 +- .../Impls_1.scala | 2 +- test/files/neg/macro-quasiquotes/Macros_1.scala | 4 +- .../neg/macro-without-xmacros-a/Impls_1.scala | 2 +- .../neg/macro-without-xmacros-b/Impls_1.scala | 2 +- test/files/neg/t5689.check | 6 +- test/files/neg/t5689.scala | 4 +- test/files/neg/t5753/Impls_Macros_1.scala | 2 +- test/files/neg/t5753/Test_2.scala | 2 +- test/files/neg/t5903a/Macros_1.scala | 4 +- test/files/neg/t5903b/Macros_1.scala | 4 +- test/files/neg/t5903c/Macros_1.scala | 4 +- test/files/neg/t5903d/Macros_1.scala | 4 +- test/files/neg/t5903e/Macros_1.scala | 4 +- test/files/neg/t6123-explaintypes-macros.check | 6 +- .../neg/t6123-explaintypes-macros/BadMac_2.scala | 4 +- .../neg/t6123-explaintypes-macros/Macros.scala | 4 +- test/files/neg/t6539/Macro_1.scala | 4 +- test/files/neg/t7157/Impls_Macros_1.scala | 26 ++++---- test/files/pos/annotated-original/M_1.scala | 4 +- .../pos/annotated-treecopy/Impls_Macros_1.scala | 4 +- .../attachments-typed-another-ident/Impls_1.scala | 4 +- .../pos/attachments-typed-ident/Impls_1.scala | 4 +- test/files/pos/t5692a/Macros_1.scala | 4 +- test/files/pos/t5692b/Macros_1.scala | 4 +- test/files/pos/t5706.scala | 13 ++-- test/files/pos/t5744/Macros_1.scala | 6 +- test/files/pos/t6047.scala | 4 +- test/files/pos/t6447.scala | 8 +-- test/files/pos/t6485a/Macros_1.scala | 4 +- test/files/pos/t6485b/Test.scala | 4 +- test/files/pos/t6516.scala | 6 +- test/files/pos/t7377/Macro_1.scala | 4 +- test/files/pos/t7461/Macros_1.scala | 4 +- test/files/pos/t7649.scala | 2 +- test/files/run/macro-abort-fresh/Macros_1.scala | 4 +- test/files/run/macro-auto-duplicate/Macros_1.scala | 4 +- test/files/run/macro-basic-ma-md-mi/Impls_1.scala | 2 +- .../run/macro-basic-ma-mdmi/Impls_Macros_1.scala | 2 +- test/files/run/macro-basic-mamd-mi/Impls_1.scala | 2 +- .../run/macro-bodyexpandstoimpl/Impls_1.scala | 7 ++- .../macro-bodyexpandstoimpl/Macros_Test_2.scala | 2 +- test/files/run/macro-bundle-repl.check | 8 +-- test/files/run/macro-bundle-repl.scala | 8 +-- .../run/macro-bundle-static/Impls_Macros_1.scala | 7 +-- .../run/macro-bundle-toplevel/Impls_Macros_1.scala | 7 +-- .../run/macro-def-infer-return-type/Impls_1.scala | 8 +-- .../run/macro-def-path-dependent/Test_1.scala | 2 +- .../run/macro-def-path-dependent/Test_2.scala | 2 +- .../run/macro-def-path-dependent/Test_3.scala | 2 +- .../run/macro-def-path-dependent/Test_4.scala | 4 +- .../run/macro-def-path-dependent/Test_5.scala | 4 +- .../run/macro-def-path-dependent/Test_6.scala | 2 +- .../macro-divergence-spurious/Impls_Macros_1.scala | 4 +- .../files/run/macro-duplicate/Impls_Macros_1.scala | 4 +- .../run/macro-enclosures/Impls_Macros_1.scala | 4 +- .../macro-expand-implicit-argument/Macros_1.scala | 4 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../macro-expand-multiple-arglists/Impls_1.scala | 2 +- .../run/macro-expand-nullary-generic/Impls_1.scala | 2 +- .../macro-expand-nullary-nongeneric/Impls_1.scala | 2 +- test/files/run/macro-expand-overload/Impls_1.scala | 2 +- test/files/run/macro-expand-override/Impls_1.scala | 2 +- .../files/run/macro-expand-recursive/Impls_1.scala | 2 +- test/files/run/macro-expand-tparams-bounds.check | 2 + .../run/macro-expand-tparams-bounds/Impls_1.scala | 6 +- .../macro-expand-tparams-explicit/Impls_1.scala | 2 +- .../macro-expand-tparams-implicit/Impls_1.scala | 2 +- .../run/macro-expand-tparams-prefix/Impls_1.scala | 8 +-- .../macro-expand-unapply-a/Impls_Macros_1.scala | 4 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../macro-impl-default-params/Impls_Macros_1.scala | 2 +- test/files/run/macro-impl-relaxed/Macros_1.scala | 10 ++-- .../macro-impl-rename-context/Impls_Macros_1.scala | 2 +- .../files/run/macro-impl-tparam-only-in-impl.check | 1 + .../macro-impl-tparam-only-in-impl/Impls_1.scala | 4 +- .../Impls_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../macro-invalidusage-badret/Impls_Macros_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../run/macro-openmacros/Impls_Macros_1.scala | 4 +- .../run/macro-parse-position/Impls_Macros_1.scala | 2 +- .../macro-quasiinvalidbody-c/Impls_Macros_1.scala | 2 +- test/files/run/macro-quasiquotes/Macros_1.scala | 4 +- test/files/run/macro-range/Common_1.scala | 4 +- .../run/macro-range/Expansion_Impossible_2.scala | 4 +- .../Impls_Macros_1.scala | 2 +- .../macro-reflective-mamd-normal-mi/Impls_1.scala | 2 +- test/files/run/macro-reify-basic/Macros_1.scala | 2 +- test/files/run/macro-reify-freevars/Macros_1.scala | 2 +- .../run/macro-reify-nested-a/Impls_Macros_1.scala | 8 +-- .../run/macro-reify-nested-b/Impls_Macros_1.scala | 8 +-- .../macro-reify-ref-to-packageless/Impls_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../run/macro-reify-splice-splice/Macros_1.scala | 2 +- .../files/run/macro-reify-staticXXX/Macros_1.scala | 6 +- test/files/run/macro-reify-tagful-a/Macros_1.scala | 2 +- .../run/macro-reify-tagless-a/Impls_Macros_1.scala | 2 +- test/files/run/macro-reify-type/Macros_1.scala | 4 +- test/files/run/macro-reify-unreify/Macros_1.scala | 2 +- test/files/run/macro-repl-basic.check | 4 +- test/files/run/macro-repl-basic.scala | 2 +- test/files/run/macro-repl-dontexpand.check | 14 +++-- test/files/run/macro-repl-dontexpand.scala | 6 +- test/files/run/macro-settings/Impls_Macros_1.scala | 4 +- .../run/macro-sip19-revised/Impls_Macros_1.scala | 4 +- test/files/run/macro-sip19/Impls_Macros_1.scala | 4 +- test/files/run/macro-system-properties.check | 6 +- test/files/run/macro-system-properties.scala | 4 +- .../Impls_1.scala | 2 +- .../macro-term-declared-in-anonymous/Impls_1.scala | 2 +- .../run/macro-term-declared-in-block/Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../run/macro-term-declared-in-class/Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_Macros_1.scala | 2 +- .../macro-term-declared-in-method/Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../macro-term-declared-in-object/Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../Impls_1.scala | 2 +- .../run/macro-term-declared-in-trait/Impls_1.scala | 2 +- .../Impls_Macros_1.scala | 6 +- .../Impls_Macros_1.scala | 6 +- .../Impls_Macros_1.scala | 6 +- .../Impls_Macros_1.scala | 6 +- .../Impls_Macros_1.scala | 4 +- .../run/macro-vampire-false-warning/Macros_1.scala | 6 +- test/files/run/repl-term-macros.check | 16 ++--- test/files/run/repl-term-macros.scala | 8 +-- test/files/run/t5713/Impls_Macros_1.scala | 4 +- test/files/run/t5753_1/Impls_Macros_1.scala | 4 +- test/files/run/t5753_2/Impls_Macros_1.scala | 2 +- test/files/run/t5894.scala | 2 +- test/files/run/t5903a/Macros_1.scala | 4 +- test/files/run/t5903b/Macros_1.scala | 4 +- test/files/run/t5903c/Macros_1.scala | 4 +- test/files/run/t5903d/Macros_1.scala | 4 +- test/files/run/t5923a/Macros_1.scala | 4 +- test/files/run/t5923c/Macros_1.scala | 4 +- test/files/run/t5923d/Macros_1.scala | 4 +- test/files/run/t5940.scala | 6 +- test/files/run/t6187.check | 8 +-- test/files/run/t6187.scala | 4 +- test/files/run/t6221/Macros_1.scala | 4 +- test/files/run/t6381.check | 4 +- test/files/run/t6381.scala | 2 +- test/files/run/t6394a/Macros_1.scala | 4 +- test/files/run/t6394b/Macros_1.scala | 4 +- test/files/run/t6662/Macro_1.scala | 4 +- .../run/t7008-scala-defined/Impls_Macros_2.scala | 4 +- test/files/run/t7008/Impls_Macros_2.scala | 4 +- test/files/run/t7047/Impls_Macros_1.scala | 4 +- test/files/run/t7157/Impls_Macros_1.scala | 4 +- test/files/run/t7240/Macros_1.scala | 4 +- test/files/run/t7375b/Macros_1.scala | 4 +- test/files/run/t7617a/Macros_1.scala | 6 +- test/files/run/t7617b/Macros_1.scala | 4 +- test/files/run/t7657/Macros_1.scala | 4 +- test/files/run/toolbox_current_run_compiles.scala | 4 +- test/files/run/typed-annotated/Macros_1.scala | 4 +- 210 files changed, 492 insertions(+), 466 deletions(-) create mode 100644 test/files/neg/macro-bundle-mixbox.check create mode 100644 test/files/neg/macro-bundle-mixbox.scala create mode 100644 test/files/run/macro-expand-tparams-bounds.check create mode 100644 test/files/run/macro-impl-tparam-only-in-impl.check (limited to 'test/files') diff --git a/test/files/neg/macro-abort/Macros_1.scala b/test/files/neg/macro-abort/Macros_1.scala index 676c112098..577e640089 100644 --- a/test/files/neg/macro-abort/Macros_1.scala +++ b/test/files/neg/macro-abort/Macros_1.scala @@ -1,8 +1,8 @@ import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { c.abort(c.enclosingPosition, "aborted") } def abort = macro impl diff --git a/test/files/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala b/test/files/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala index 97780ef503..ae34815d37 100644 --- a/test/files/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala +++ b/test/files/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { diff --git a/test/files/neg/macro-bundle-abstract.check b/test/files/neg/macro-bundle-abstract.check index 4b07adcc95..8ef59106b8 100644 --- a/test/files/neg/macro-bundle-abstract.check +++ b/test/files/neg/macro-bundle-abstract.check @@ -1,4 +1,4 @@ -macro-bundle-abstract.scala:5: error: class Bundle$Bundle needs to be abstract, since method deferred in trait Bundle of type => Int is not defined -trait Bundle extends Macro { +macro-bundle-abstract.scala:4: error: class Bundle$Bundle needs to be abstract, since method deferred in trait Bundle of type => Int is not defined +trait Bundle extends BlackboxMacro { ^ one error found diff --git a/test/files/neg/macro-bundle-abstract.scala b/test/files/neg/macro-bundle-abstract.scala index 2b302045da..f7778d03be 100644 --- a/test/files/neg/macro-bundle-abstract.scala +++ b/test/files/neg/macro-bundle-abstract.scala @@ -1,8 +1,7 @@ import scala.language.experimental.macros -import scala.reflect.macros.Macro -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxMacro -trait Bundle extends Macro { +trait Bundle extends BlackboxMacro { def deferred: Int def impl = ??? } diff --git a/test/files/neg/macro-bundle-class.check b/test/files/neg/macro-bundle-class.check index 92695390ab..8fd04f1303 100644 --- a/test/files/neg/macro-bundle-class.check +++ b/test/files/neg/macro-bundle-class.check @@ -1,4 +1,4 @@ -macro-bundle-class.scala:10: error: macro bundles must be monomorphic traits extending scala.reflect.macros.Macro and not implementing its `val c: Context` member +macro-bundle-class.scala:10: error: macro bundles must be monomorphic traits extending either BlackboxMacro or WhiteboxMacro and not implementing their `val c: BlackboxContext/WhiteboxContext` member def foo = macro Bundle.impl ^ one error found diff --git a/test/files/neg/macro-bundle-class.scala b/test/files/neg/macro-bundle-class.scala index 4b92cdd40f..024e2dbaaa 100644 --- a/test/files/neg/macro-bundle-class.scala +++ b/test/files/neg/macro-bundle-class.scala @@ -1,8 +1,8 @@ import scala.language.experimental.macros -import scala.reflect.macros.Macro -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxMacro +import scala.reflect.macros.BlackboxContext -class Bundle(val c: Context) extends Macro { +class Bundle(val c: BlackboxContext) extends BlackboxMacro { def impl = ??? } diff --git a/test/files/neg/macro-bundle-mixbox.check b/test/files/neg/macro-bundle-mixbox.check new file mode 100644 index 0000000000..4f8cedcece --- /dev/null +++ b/test/files/neg/macro-bundle-mixbox.check @@ -0,0 +1,4 @@ +macro-bundle-mixbox.scala:9: error: macro bundles must be monomorphic traits extending either BlackboxMacro or WhiteboxMacro and not implementing their `val c: BlackboxContext/WhiteboxContext` member + def foo = macro Bundle.impl + ^ +one error found diff --git a/test/files/neg/macro-bundle-mixbox.scala b/test/files/neg/macro-bundle-mixbox.scala new file mode 100644 index 0000000000..1e36f3d94c --- /dev/null +++ b/test/files/neg/macro-bundle-mixbox.scala @@ -0,0 +1,10 @@ +import scala.language.experimental.macros +import scala.reflect.macros.{BlackboxMacro, WhiteboxMacro} + +trait Bundle extends BlackboxMacro with WhiteboxMacro { + def impl = ??? +} + +object Macros { + def foo = macro Bundle.impl +} \ No newline at end of file diff --git a/test/files/neg/macro-bundle-object.check b/test/files/neg/macro-bundle-object.check index 8c19271b51..e148e86969 100644 --- a/test/files/neg/macro-bundle-object.check +++ b/test/files/neg/macro-bundle-object.check @@ -1,6 +1,6 @@ -macro-bundle-object.scala:11: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context): c.Expr[Any] - or : (c: scala.reflect.macros.Context): c.Tree +macro-bundle-object.scala:10: error: macro implementation has wrong shape: + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext): c.Tree found : : Nothing number of parameter sections differ def foo = macro Bundle.impl diff --git a/test/files/neg/macro-bundle-object.scala b/test/files/neg/macro-bundle-object.scala index 98c4238a62..105c81f1f5 100644 --- a/test/files/neg/macro-bundle-object.scala +++ b/test/files/neg/macro-bundle-object.scala @@ -1,9 +1,8 @@ import scala.language.experimental.macros -import scala.reflect.macros.Macro -import scala.reflect.macros.Context +import scala.reflect.macros.{BlackboxMacro, BlackboxContext} -object Bundle extends Macro { - val c: Context = ??? +object Bundle extends BlackboxMacro { + val c: BlackboxContext = ??? def impl = ??? } diff --git a/test/files/neg/macro-bundle-polymorphic.check b/test/files/neg/macro-bundle-polymorphic.check index 204bd30bca..07c5f551b1 100644 --- a/test/files/neg/macro-bundle-polymorphic.check +++ b/test/files/neg/macro-bundle-polymorphic.check @@ -1,10 +1,10 @@ -macro-bundle-polymorphic.scala:10: error: macro bundles must be monomorphic traits extending scala.reflect.macros.Macro and not implementing its `val c: Context` member +macro-bundle-polymorphic.scala:9: error: macro bundles must be monomorphic traits extending either BlackboxMacro or WhiteboxMacro and not implementing their `val c: BlackboxContext/WhiteboxContext` member def foo = macro Bundle.impl ^ -macro-bundle-polymorphic.scala:11: error: macro bundles must be monomorphic traits extending scala.reflect.macros.Macro and not implementing its `val c: Context` member +macro-bundle-polymorphic.scala:10: error: macro bundles must be monomorphic traits extending either BlackboxMacro or WhiteboxMacro and not implementing their `val c: BlackboxContext/WhiteboxContext` member def foo = macro Bundle[Int].impl ^ -macro-bundle-polymorphic.scala:12: error: macro bundles must be monomorphic traits extending scala.reflect.macros.Macro and not implementing its `val c: Context` member +macro-bundle-polymorphic.scala:11: error: macro bundles must be monomorphic traits extending either BlackboxMacro or WhiteboxMacro and not implementing their `val c: BlackboxContext/WhiteboxContext` member def foo = macro Bundle[Int, Nothing].impl ^ three errors found diff --git a/test/files/neg/macro-bundle-polymorphic.scala b/test/files/neg/macro-bundle-polymorphic.scala index 0468d841bd..faf1e2e9e5 100644 --- a/test/files/neg/macro-bundle-polymorphic.scala +++ b/test/files/neg/macro-bundle-polymorphic.scala @@ -1,8 +1,7 @@ import scala.language.experimental.macros -import scala.reflect.macros.Macro -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxMacro -trait Bundle[T] extends Macro { +trait Bundle[T] extends BlackboxMacro { def impl = ??? } diff --git a/test/files/neg/macro-bundle-trait.check b/test/files/neg/macro-bundle-trait.check index 972788c577..bf906a5310 100644 --- a/test/files/neg/macro-bundle-trait.check +++ b/test/files/neg/macro-bundle-trait.check @@ -1,4 +1,4 @@ -macro-bundle-trait.scala:11: error: macro bundles must be monomorphic traits extending scala.reflect.macros.Macro and not implementing its `val c: Context` member +macro-bundle-trait.scala:11: error: macro bundles must be monomorphic traits extending either BlackboxMacro or WhiteboxMacro and not implementing their `val c: BlackboxContext/WhiteboxContext` member def foo = macro Bundle.impl ^ one error found diff --git a/test/files/neg/macro-bundle-trait.scala b/test/files/neg/macro-bundle-trait.scala index ddc87f6db3..62ade49953 100644 --- a/test/files/neg/macro-bundle-trait.scala +++ b/test/files/neg/macro-bundle-trait.scala @@ -1,9 +1,9 @@ import scala.language.experimental.macros -import scala.reflect.macros.Macro -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxMacro +import scala.reflect.macros.BlackboxContext -trait Bundle extends Macro { - val c: Context = ??? +trait Bundle extends BlackboxMacro { + val c: BlackboxContext = ??? def impl = ??? } diff --git a/test/files/neg/macro-cyclic/Impls_Macros_1.scala b/test/files/neg/macro-cyclic/Impls_Macros_1.scala index ac9b7938db..ba08345bcc 100644 --- a/test/files/neg/macro-cyclic/Impls_Macros_1.scala +++ b/test/files/neg/macro-cyclic/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { c.universe.reify { implicitly[SourceLocation] } } diff --git a/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala b/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala index 3983f590dc..23fcdd6445 100644 --- a/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala +++ b/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros trait Complex[T] @@ -6,7 +6,7 @@ trait Complex[T] class Foo(val foo: Foo) object Complex { - def impl[T: c.WeakTypeTag](c: Context): c.Expr[Complex[T]] = { + def impl[T: c.WeakTypeTag](c: BlackboxContext): c.Expr[Complex[T]] = { import c.universe._ val tpe = weakTypeOf[T] for (f <- tpe.declarations.collect{case f: TermSymbol if f.isParamAccessor && !f.isMethod => f}) { diff --git a/test/files/neg/macro-exception/Macros_1.scala b/test/files/neg/macro-exception/Macros_1.scala index 60e4020aec..7bd8415e4f 100644 --- a/test/files/neg/macro-exception/Macros_1.scala +++ b/test/files/neg/macro-exception/Macros_1.scala @@ -1,8 +1,8 @@ import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { throw new Exception() } def exception = macro impl diff --git a/test/files/neg/macro-false-deprecation-warning/Impls_Macros_1.scala b/test/files/neg/macro-false-deprecation-warning/Impls_Macros_1.scala index 6dc2ea114b..1bd808d55d 100644 --- a/test/files/neg/macro-false-deprecation-warning/Impls_Macros_1.scala +++ b/test/files/neg/macro-false-deprecation-warning/Impls_Macros_1.scala @@ -1,11 +1,11 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Helper { def unapplySeq[T](x: List[T]): Option[Seq[T]] = } object Macros { - def impl[T: c.WeakTypeTag](c: Context)(x: c.Expr[List[T]]) = { + def impl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Expr[List[T]]) = { c.universe.reify(Helper.unapplySeq(x.splice)) } diff --git a/test/files/neg/macro-invalidimpl.check b/test/files/neg/macro-invalidimpl.check index e39cc8105b..432da4d00b 100644 --- a/test/files/neg/macro-invalidimpl.check +++ b/test/files/neg/macro-invalidimpl.check @@ -19,28 +19,28 @@ macro [].[[]] def foo(x: Any) = macro Impls4.foo ^ Macros_Test_2.scala:26: error: ambiguous reference to overloaded definition, -both method foo in object Impls5 of type (c: scala.reflect.macros.Context)(x: c.Expr[Any], y: c.Expr[Any])Nothing -and method foo in object Impls5 of type (c: scala.reflect.macros.Context)(x: c.Expr[Any])Nothing +both method foo in object Impls5 of type (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Any], y: c.Expr[Any])Nothing +and method foo in object Impls5 of type (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Any])Nothing match expected type ? def foo(x: Any) = macro Impls5.foo ^ Macros_Test_2.scala:27: error: ambiguous reference to overloaded definition, -both method foo in object Impls5 of type (c: scala.reflect.macros.Context)(x: c.Expr[Any], y: c.Expr[Any])Nothing -and method foo in object Impls5 of type (c: scala.reflect.macros.Context)(x: c.Expr[Any])Nothing +both method foo in object Impls5 of type (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Any], y: c.Expr[Any])Nothing +and method foo in object Impls5 of type (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Any])Nothing match expected type ? def foo(x: Any, y: Any) = macro Impls5.foo ^ Macros_Test_2.scala:31: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context): c.Expr[Unit] - or : (c: scala.reflect.macros.Context): c.Tree - found : (c: scala.reflect.macros.Context)(): c.Expr[Unit] + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Unit] + or : (c: scala.reflect.macros.BlackboxContext): c.Tree + found : (c: scala.reflect.macros.BlackboxContext)(): c.Expr[Unit] number of parameter sections differ def foo1 = macro Impls6.fooEmpty ^ Macros_Test_2.scala:32: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context)(): c.Expr[Unit] - or : (c: scala.reflect.macros.Context)(): c.Tree - found : (c: scala.reflect.macros.Context): c.Expr[Unit] + required: (c: scala.reflect.macros.BlackboxContext)(): c.Expr[Unit] + or : (c: scala.reflect.macros.BlackboxContext)(): c.Tree + found : (c: scala.reflect.macros.BlackboxContext): c.Expr[Unit] number of parameter sections differ def bar1() = macro Impls6.fooNullary ^ diff --git a/test/files/neg/macro-invalidimpl/Impls_1.scala b/test/files/neg/macro-invalidimpl/Impls_1.scala index 9f48ab7ad9..b85ac9ee43 100644 --- a/test/files/neg/macro-invalidimpl/Impls_1.scala +++ b/test/files/neg/macro-invalidimpl/Impls_1.scala @@ -1,39 +1,39 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext class Impls1 { - def foo(c: Context)(x: c.Expr[Any]) = ??? + def foo(c: BlackboxContext)(x: c.Expr[Any]) = ??? } object Impls2 { - def foo(c: Context)(x: c.Expr[Any]) = ??? + def foo(c: BlackboxContext)(x: c.Expr[Any]) = ??? } trait MacroHelpers { object Impls4 { - def foo(c: Context)(x: c.Expr[Any]) = x + def foo(c: BlackboxContext)(x: c.Expr[Any]) = x } } object Impls5 { - def foo(c: Context)(x: c.Expr[Any]) = ??? - def foo(c: Context)(x: c.Expr[Any], y: c.Expr[Any]) = ??? + def foo(c: BlackboxContext)(x: c.Expr[Any]) = ??? + def foo(c: BlackboxContext)(x: c.Expr[Any], y: c.Expr[Any]) = ??? } object Impls6 { - def fooNullary(c: Context) = { + def fooNullary(c: BlackboxContext) = { import c.universe._ c.Expr[Unit](q"""Predef.println("it works")""") } - def fooEmpty(c: Context)() = fooNullary(c) + def fooEmpty(c: BlackboxContext)() = fooNullary(c) } object Impls7 { - def foo[U <: Int](c: Context) = ??? + def foo[U <: Int](c: BlackboxContext) = ??? } package foo { object Impls8 { - private[foo] def impl(c: Context) = ??? + private[foo] def impl(c: BlackboxContext) = ??? } } \ No newline at end of file diff --git a/test/files/neg/macro-invalidimpl/Macros_Test_2.scala b/test/files/neg/macro-invalidimpl/Macros_Test_2.scala index 8aae9553f5..0df7d2e0c5 100644 --- a/test/files/neg/macro-invalidimpl/Macros_Test_2.scala +++ b/test/files/neg/macro-invalidimpl/Macros_Test_2.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros1 { val impls = new Impls1 @@ -12,7 +12,7 @@ object Macros2 { class Macros3 { object Impls3 { - def foo(c: Context)(x: c.Expr[Any]) = ??? + def foo(c: BlackboxContext)(x: c.Expr[Any]) = ??? } def foo(x: Any) = macro Impls3.foo diff --git a/test/files/neg/macro-invalidret.check b/test/files/neg/macro-invalidret.check index 6cf62c292b..19adc70fb3 100644 --- a/test/files/neg/macro-invalidret.check +++ b/test/files/neg/macro-invalidret.check @@ -1,14 +1,14 @@ Macros_Test_2.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context): c.Expr[Any] - or : (c: scala.reflect.macros.Context): c.Tree - found : (c: scala.reflect.macros.Context): Int + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext): c.Tree + found : (c: scala.reflect.macros.BlackboxContext): Int type mismatch for return type: Int does not conform to c.Expr[Any] def foo1 = macro Impls.foo1 ^ Macros_Test_2.scala:3: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context): c.Expr[Any] - or : (c: scala.reflect.macros.Context): c.Tree - found : (c: scala.reflect.macros.Context): reflect.runtime.universe.Literal + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext): c.Tree + found : (c: scala.reflect.macros.BlackboxContext): reflect.runtime.universe.Literal type mismatch for return type: reflect.runtime.universe.Literal does not conform to c.Expr[Any] def foo2 = macro Impls.foo2 ^ diff --git a/test/files/neg/macro-invalidret/Impls_1.scala b/test/files/neg/macro-invalidret/Impls_1.scala index a58af1a23c..d957b74512 100644 --- a/test/files/neg/macro-invalidret/Impls_1.scala +++ b/test/files/neg/macro-invalidret/Impls_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import scala.reflect.runtime.{universe => ru} object Impls { - def foo1(c: Context) = 2 - def foo2(c: Context) = ru.Literal(ru.Constant(42)) + def foo1(c: BlackboxContext) = 2 + def foo2(c: BlackboxContext) = ru.Literal(ru.Constant(42)) } diff --git a/test/files/neg/macro-invalidshape/Impls_1.scala b/test/files/neg/macro-invalidshape/Impls_1.scala index 4467021545..3d5da9a2ed 100644 --- a/test/files/neg/macro-invalidshape/Impls_1.scala +++ b/test/files/neg/macro-invalidshape/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-invalidshape/Macros_Test_2.scala b/test/files/neg/macro-invalidshape/Macros_Test_2.scala index 819844b9f1..8f643ab281 100644 --- a/test/files/neg/macro-invalidshape/Macros_Test_2.scala +++ b/test/files/neg/macro-invalidshape/Macros_Test_2.scala @@ -3,7 +3,7 @@ object Macros { def foo2(x: Any) = macro Impls.foo(null)(null) def foo3(x: Any) = macro {2; Impls.foo} { - def impl(c: scala.reflect.macros.Context) = { import c.universe._; c.Expr[Unit](q"()") } + def impl(c: scala.reflect.macros.BlackboxContext) = { import c.universe._; c.Expr[Unit](q"()") } def foo = macro impl foo } diff --git a/test/files/neg/macro-invalidsig-params-badtype.check b/test/files/neg/macro-invalidsig-params-badtype.check index 86aa08291f..e0cd63fbe4 100644 --- a/test/files/neg/macro-invalidsig-params-badtype.check +++ b/test/files/neg/macro-invalidsig-params-badtype.check @@ -1,7 +1,7 @@ Impls_Macros_1.scala:8: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Any] - or : (c: scala.reflect.macros.Context)(x: c.Tree): c.Tree - found : (c: scala.reflect.macros.Context)(x: Int): Nothing + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int]): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree): c.Tree + found : (c: scala.reflect.macros.BlackboxContext)(x: Int): Nothing type mismatch for parameter x: c.Expr[Int] does not conform to Int def foo(x: Int) = macro Impls.foo ^ diff --git a/test/files/neg/macro-invalidsig-params-badtype/Impls_Macros_1.scala b/test/files/neg/macro-invalidsig-params-badtype/Impls_Macros_1.scala index 175683d6d3..5f468424bd 100644 --- a/test/files/neg/macro-invalidsig-params-badtype/Impls_Macros_1.scala +++ b/test/files/neg/macro-invalidsig-params-badtype/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: Int) = ??? diff --git a/test/files/neg/macro-invalidsig.check b/test/files/neg/macro-invalidsig.check index 732380d4b3..42b8db5628 100644 --- a/test/files/neg/macro-invalidsig.check +++ b/test/files/neg/macro-invalidsig.check @@ -1,77 +1,77 @@ Macros_Test_2.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context): c.Expr[Any] - or : (c: scala.reflect.macros.Context): c.Tree - found : (c: scala.reflect.macros.Context)(implicit evidence$2: Numeric[U]): c.universe.Literal + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext): c.Tree + found : (c: scala.reflect.macros.BlackboxContext)(implicit evidence$2: Numeric[U]): c.universe.Literal macro implementations cannot have implicit parameters other than WeakTypeTag evidences def foo[U] = macro Impls1.foo[U] ^ Macros_Test_2.scala:6: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context): c.Expr[Any] - or : (c: scala.reflect.macros.Context): c.Tree + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext): c.Tree found : : Nothing number of parameter sections differ def foo = macro Impls2.foo ^ Macros_Test_2.scala:10: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context): c.Expr[Any] - or : (c: scala.reflect.macros.Context): c.Tree + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext): c.Tree found : (c: scala.reflect.api.Universe): Nothing -type mismatch for parameter c: scala.reflect.macros.Context does not conform to scala.reflect.api.Universe +type mismatch for parameter c: scala.reflect.macros.BlackboxContext does not conform to scala.reflect.api.Universe def foo = macro Impls3.foo ^ Macros_Test_2.scala:14: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context): c.Expr[Any] - or : (c: scala.reflect.macros.Context): c.Tree - found : (cs: scala.reflect.macros.Context*): Nothing + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext): c.Tree + found : (cs: scala.reflect.macros.BlackboxContext*): Nothing types incompatible for parameter cs: corresponding is not a vararg parameter def foo = macro Impls4.foo ^ Macros_Test_2.scala:18: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context)(x: c.Expr[Any]): c.Expr[Any] - or : (c: scala.reflect.macros.Context)(x: c.Tree): c.Tree - found : (c: scala.reflect.macros.Context): Nothing + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Any]): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree): c.Tree + found : (c: scala.reflect.macros.BlackboxContext): Nothing number of parameter sections differ def foo(x: Any) = macro Impls5.foo ^ Macros_Test_2.scala:22: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Unit] - or : (c: scala.reflect.macros.Context)(x: c.Tree): c.Tree - found : (c: scala.reflect.macros.Context)(implicit x: c.Expr[Int]): c.Expr[Unit] + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int]): c.Expr[Unit] + or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree): c.Tree + found : (c: scala.reflect.macros.BlackboxContext)(implicit x: c.Expr[Int]): c.Expr[Unit] macro implementations cannot have implicit parameters other than WeakTypeTag evidences def foo[U](x: Int) = macro Impls6.foo[T, U] ^ Macros_Test_2.scala:26: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Any] - or : (c: scala.reflect.macros.Context)(x: c.Tree): c.Tree - found : (c: scala.reflect.macros.Context)(x: c.Expr[Int], y: c.Expr[Int]): Nothing + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int]): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree): c.Tree + found : (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int]): Nothing parameter lists have different length, found extra parameter y: c.Expr[Int] def foo(x: Int) = macro Impls7.foo ^ Macros_Test_2.scala:30: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Any] - or : (c: scala.reflect.macros.Context)(x: c.Tree): c.Tree - found : (c: scala.reflect.macros.Context)(x: c.universe.Symbol): Nothing + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int]): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree): c.Tree + found : (c: scala.reflect.macros.BlackboxContext)(x: c.universe.Symbol): Nothing type mismatch for parameter x: c.Expr[Int] does not conform to c.universe.Symbol def foo(x: Int) = macro Impls8.foo ^ Macros_Test_2.scala:34: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] - or : (c: scala.reflect.macros.Context)(x: c.Tree, y: c.Tree): c.Tree - found : (c: scala.reflect.macros.Context)(xs: c.Expr[Int]*): Nothing + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree, y: c.Tree): c.Tree + found : (c: scala.reflect.macros.BlackboxContext)(xs: c.Expr[Int]*): Nothing parameter lists have different length, required extra parameter y: c.Expr[Int] def foo(x: Int, y: Int) = macro Impls9.foo ^ Macros_Test_2.scala:38: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] - or : (c: scala.reflect.macros.Context)(x: c.Tree, y: c.Tree): c.Tree - found : (c: scala.reflect.macros.Context)(y: c.Expr[Int], x: c.Expr[Int]): Nothing + required: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext)(x: c.Tree, y: c.Tree): c.Tree + found : (c: scala.reflect.macros.BlackboxContext)(y: c.Expr[Int], x: c.Expr[Int]): Nothing parameter names differ: x != y def foo(x: Int, y: Int) = macro Impls10.foo ^ Macros_Test_2.scala:42: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context): c.Expr[Any] - or : (c: scala.reflect.macros.Context): c.Tree - found : (c: scala.reflect.macros.Context)(U: c.universe.Type): Nothing + required: (c: scala.reflect.macros.BlackboxContext): c.Expr[Any] + or : (c: scala.reflect.macros.BlackboxContext): c.Tree + found : (c: scala.reflect.macros.BlackboxContext)(U: c.universe.Type): Nothing number of parameter sections differ def foo[U] = macro Impls11.foo[U] ^ @@ -81,13 +81,13 @@ Macros_Test_2.scala:46: error: type arguments [U] do not conform to method foo's Macros_Test_2.scala:50: error: type arguments [U] do not conform to method foo's type parameter bounds [U <: String] def foo[U <: Int] = macro Impls13.foo[U] ^ -Macros_Test_2.scala:54: error: wrong number of type parameters for method foo: [U](c: scala.reflect.macros.Context)(implicit evidence$4: c.WeakTypeTag[U])Nothing +Macros_Test_2.scala:54: error: wrong number of type parameters for method foo: [U](c: scala.reflect.macros.BlackboxContext)(implicit evidence$4: c.WeakTypeTag[U])Nothing def foo = macro Impls14.foo ^ -Macros_Test_2.scala:59: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.Context)(implicit evidence$5: c.WeakTypeTag[T], implicit evidence$6: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit] +Macros_Test_2.scala:59: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.BlackboxContext)(implicit evidence$5: c.WeakTypeTag[T], implicit evidence$6: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit] def foo15[V] = macro Impls15.foo ^ -Macros_Test_2.scala:60: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.Context)(implicit evidence$7: c.WeakTypeTag[T], implicit evidence$8: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit] +Macros_Test_2.scala:60: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.BlackboxContext)(implicit evidence$7: c.WeakTypeTag[T], implicit evidence$8: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit] def foo16[V] = macro Impls16.foo[V] ^ 16 errors found diff --git a/test/files/neg/macro-invalidsig/Impls_1.scala b/test/files/neg/macro-invalidsig/Impls_1.scala index d16ed26386..7c98160925 100644 --- a/test/files/neg/macro-invalidsig/Impls_1.scala +++ b/test/files/neg/macro-invalidsig/Impls_1.scala @@ -1,8 +1,8 @@ import scala.reflect.runtime.universe._ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Impls1 { - def foo[U: c.WeakTypeTag: Numeric](c: Context) = { import c.universe._; q"42" } + def foo[U: c.WeakTypeTag: Numeric](c: BlackboxContext) = { import c.universe._; q"42" } } object Impls2 { @@ -14,15 +14,15 @@ object Impls3 { } object Impls4 { - def foo(cs: Context*) = ??? + def foo(cs: BlackboxContext*) = ??? } object Impls5 { - def foo(c: Context) = ??? + def foo(c: BlackboxContext) = ??? } object Impls6 { - def foo[T, U: c.WeakTypeTag](c: Context)(implicit x: c.Expr[Int]) = { + def foo[T, U: c.WeakTypeTag](c: BlackboxContext)(implicit x: c.Expr[Int]) = { import c.{prefix => prefix} import c.universe._ c.Expr[Unit](q""" @@ -34,39 +34,39 @@ object Impls6 { } object Impls7 { - def foo(c: Context)(x: c.Expr[Int], y: c.Expr[Int]) = ??? + def foo(c: BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int]) = ??? } object Impls8 { - def foo(c: Context)(x: c.universe.Symbol) = ??? + def foo(c: BlackboxContext)(x: c.universe.Symbol) = ??? } object Impls9 { - def foo(c: Context)(xs: c.Expr[Int]*) = ??? + def foo(c: BlackboxContext)(xs: c.Expr[Int]*) = ??? } object Impls10 { - def foo(c: Context)(y: c.Expr[Int], x: c.Expr[Int]) = ??? + def foo(c: BlackboxContext)(y: c.Expr[Int], x: c.Expr[Int]) = ??? } object Impls11 { - def foo[U](c: Context)(U: c.universe.Type) = ??? + def foo[U](c: BlackboxContext)(U: c.universe.Type) = ??? } object Impls12 { - def foo[U <: String](c: Context) = ??? + def foo[U <: String](c: BlackboxContext) = ??? } object Impls13 { - def foo[U <: String](c: Context) = ??? + def foo[U <: String](c: BlackboxContext) = ??? } object Impls14 { - def foo[U: c.WeakTypeTag](c: Context) = ??? + def foo[U: c.WeakTypeTag](c: BlackboxContext) = ??? } object Impls15 { - def foo[T: c.WeakTypeTag, U: c.WeakTypeTag, V](c: Context)(implicit V: c.WeakTypeTag[V]): c.Expr[Unit] = { + def foo[T: c.WeakTypeTag, U: c.WeakTypeTag, V](c: BlackboxContext)(implicit V: c.WeakTypeTag[V]): c.Expr[Unit] = { import c.universe._ println(implicitly[c.WeakTypeTag[T]]) println(implicitly[c.WeakTypeTag[U]]) @@ -76,7 +76,7 @@ object Impls15 { } object Impls16 { - def foo[T: c.WeakTypeTag, U: c.WeakTypeTag, V](c: Context)(implicit V: c.WeakTypeTag[V]): c.Expr[Unit] = { + def foo[T: c.WeakTypeTag, U: c.WeakTypeTag, V](c: BlackboxContext)(implicit V: c.WeakTypeTag[V]): c.Expr[Unit] = { import c.universe._ println(implicitly[c.WeakTypeTag[T]]) println(implicitly[c.WeakTypeTag[U]]) diff --git a/test/files/neg/macro-invalidusage-badargs/Impls_1.scala b/test/files/neg/macro-invalidusage-badargs/Impls_1.scala index 52c9f9c3e9..678cb53929 100644 --- a/test/files/neg/macro-invalidusage-badargs/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-badargs/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = x diff --git a/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala b/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala index 74c163596a..393f7de976 100644 --- a/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-badbounds/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo[U <: String](c: Ctx) = { import c.universe._; c.Expr[Unit](q"()") } diff --git a/test/files/neg/macro-invalidusage-badtargs/Impls_1.scala b/test/files/neg/macro-invalidusage-badtargs/Impls_1.scala index 52c9f9c3e9..678cb53929 100644 --- a/test/files/neg/macro-invalidusage-badtargs/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-badtargs/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = x diff --git a/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala b/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala index 11b6a8c3b0..15894efb68 100644 --- a/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/neg/macro-invalidusage-nontypeable/Impls_Macros_1.scala b/test/files/neg/macro-invalidusage-nontypeable/Impls_Macros_1.scala index 869a5a41fa..44e508a1c6 100644 --- a/test/files/neg/macro-invalidusage-nontypeable/Impls_Macros_1.scala +++ b/test/files/neg/macro-invalidusage-nontypeable/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/neg/macro-invalidusage-presuper/Impls_1.scala b/test/files/neg/macro-invalidusage-presuper/Impls_1.scala index c4b57233c9..02c87b5a81 100644 --- a/test/files/neg/macro-invalidusage-presuper/Impls_1.scala +++ b/test/files/neg/macro-invalidusage-presuper/Impls_1.scala @@ -1,5 +1,5 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Impls { - def impl(c: Context) = { import c.universe._; c.Expr[Unit](q"()") } + def impl(c: BlackboxContext) = { import c.universe._; c.Expr[Unit](q"()") } } \ No newline at end of file diff --git a/test/files/neg/macro-noexpand/Impls_1.scala b/test/files/neg/macro-noexpand/Impls_1.scala index 4467021545..3d5da9a2ed 100644 --- a/test/files/neg/macro-noexpand/Impls_1.scala +++ b/test/files/neg/macro-noexpand/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-nontypeablebody/Impls_1.scala b/test/files/neg/macro-nontypeablebody/Impls_1.scala index 4467021545..3d5da9a2ed 100644 --- a/test/files/neg/macro-nontypeablebody/Impls_1.scala +++ b/test/files/neg/macro-nontypeablebody/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Any]) = ??? diff --git a/test/files/neg/macro-override-macro-overrides-abstract-method-a/Impls_Macros_1.scala b/test/files/neg/macro-override-macro-overrides-abstract-method-a/Impls_Macros_1.scala index e43264f52f..0e8a5f3b01 100644 --- a/test/files/neg/macro-override-macro-overrides-abstract-method-a/Impls_Macros_1.scala +++ b/test/files/neg/macro-override-macro-overrides-abstract-method-a/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def impl(c: Ctx)(x: c.Expr[Int]) = x diff --git a/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala b/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala index f5b2555aa5..c98279b2b8 100644 --- a/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala +++ b/test/files/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala @@ -1,8 +1,8 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros trait T { def t(): Unit } trait A { def t(): Unit = () } -object Macro { def t(c: Context)(): c.Expr[Unit] = c.universe.reify(()) } +object Macro { def t(c: BlackboxContext)(): c.Expr[Unit] = c.universe.reify(()) } trait C extends T { self: A => override def t(): Unit = macro Macro.t } diff --git a/test/files/neg/macro-override-method-overrides-macro/Impls_1.scala b/test/files/neg/macro-override-method-overrides-macro/Impls_1.scala index 64a9299ee6..f2d3f67ccc 100644 --- a/test/files/neg/macro-override-method-overrides-macro/Impls_1.scala +++ b/test/files/neg/macro-override-method-overrides-macro/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def impl(c: Ctx)(tag: String, x: c.Expr[_]) = { diff --git a/test/files/neg/macro-quasiquotes/Macros_1.scala b/test/files/neg/macro-quasiquotes/Macros_1.scala index 17c1034720..7f0219e6ac 100644 --- a/test/files/neg/macro-quasiquotes/Macros_1.scala +++ b/test/files/neg/macro-quasiquotes/Macros_1.scala @@ -1,7 +1,7 @@ import language.experimental.macros -import scala.reflect.macros.Macro +import scala.reflect.macros.BlackboxMacro -trait Impls extends Macro { +trait Impls extends BlackboxMacro { import c.universe._ def impl1(x: Expr[Int]) = q"println(x)" def impl2(x: Tree) = q"println(x)" diff --git a/test/files/neg/macro-without-xmacros-a/Impls_1.scala b/test/files/neg/macro-without-xmacros-a/Impls_1.scala index 868616aace..6b73a96184 100644 --- a/test/files/neg/macro-without-xmacros-a/Impls_1.scala +++ b/test/files/neg/macro-without-xmacros-a/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo_impl(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { diff --git a/test/files/neg/macro-without-xmacros-b/Impls_1.scala b/test/files/neg/macro-without-xmacros-b/Impls_1.scala index 868616aace..6b73a96184 100644 --- a/test/files/neg/macro-without-xmacros-b/Impls_1.scala +++ b/test/files/neg/macro-without-xmacros-b/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo_impl(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { diff --git a/test/files/neg/t5689.check b/test/files/neg/t5689.check index 8cf0534e77..e74de40280 100644 --- a/test/files/neg/t5689.check +++ b/test/files/neg/t5689.check @@ -1,7 +1,7 @@ t5689.scala:4: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context)(i: c.Expr[Double]): c.Expr[String] - or : (c: scala.reflect.macros.Context)(i: c.Tree): c.Tree - found : (c: scala.reflect.macros.Context)(i: c.Expr[Double]): c.Expr[Int] + required: (c: scala.reflect.macros.BlackboxContext)(i: c.Expr[Double]): c.Expr[String] + or : (c: scala.reflect.macros.BlackboxContext)(i: c.Tree): c.Tree + found : (c: scala.reflect.macros.BlackboxContext)(i: c.Expr[Double]): c.Expr[Int] type mismatch for return type: c.Expr[Int] does not conform to c.Expr[String] def returnsString(i: Double): String = macro returnsIntImpl ^ diff --git a/test/files/neg/t5689.scala b/test/files/neg/t5689.scala index 3266039c35..d0e468849d 100644 --- a/test/files/neg/t5689.scala +++ b/test/files/neg/t5689.scala @@ -1,6 +1,6 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { def returnsString(i: Double): String = macro returnsIntImpl - def returnsIntImpl(c: Context)(i: c.Expr[Double]): c.Expr[Int] = ??? + def returnsIntImpl(c: BlackboxContext)(i: c.Expr[Double]): c.Expr[Int] = ??? } diff --git a/test/files/neg/t5753/Impls_Macros_1.scala b/test/files/neg/t5753/Impls_Macros_1.scala index 1d9c26458c..f93d731d40 100644 --- a/test/files/neg/t5753/Impls_Macros_1.scala +++ b/test/files/neg/t5753/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} trait Impls { def impl(c: Ctx)(x: c.Expr[Any]) = x diff --git a/test/files/neg/t5753/Test_2.scala b/test/files/neg/t5753/Test_2.scala index 2369b18e76..f1cad67fed 100644 --- a/test/files/neg/t5753/Test_2.scala +++ b/test/files/neg/t5753/Test_2.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Macros extends Impls { def foo(x: Any) = macro impl diff --git a/test/files/neg/t5903a/Macros_1.scala b/test/files/neg/t5903a/Macros_1.scala index e82be0fc68..9fc3bfe261 100644 --- a/test/files/neg/t5903a/Macros_1.scala +++ b/test/files/neg/t5903a/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros trait Tree @@ -13,7 +13,7 @@ object NewQuasiquotes { } object QuasiquoteMacros { - def unapplyImpl(c: Context)(t: c.Tree) = { + def unapplyImpl(c: BlackboxContext)(t: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/neg/t5903b/Macros_1.scala b/test/files/neg/t5903b/Macros_1.scala index b1b875969d..46f0eee0f1 100644 --- a/test/files/neg/t5903b/Macros_1.scala +++ b/test/files/neg/t5903b/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl[T: c.WeakTypeTag](c: Context)(x: c.Tree) = { + def unapplyImpl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/neg/t5903c/Macros_1.scala b/test/files/neg/t5903c/Macros_1.scala index 70efab3101..281a06e93c 100644 --- a/test/files/neg/t5903c/Macros_1.scala +++ b/test/files/neg/t5903c/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl[T: c.WeakTypeTag](c: Context)(x: c.Tree) = { + def unapplyImpl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Tree) = { import c.universe._ if (!(c.weakTypeOf[Int] =:= c.weakTypeOf[T])) c.abort(c.enclosingPosition, s"${c.weakTypeOf[T]} is not supported") else { diff --git a/test/files/neg/t5903d/Macros_1.scala b/test/files/neg/t5903d/Macros_1.scala index 15ff226cff..5dd6220e1a 100644 --- a/test/files/neg/t5903d/Macros_1.scala +++ b/test/files/neg/t5903d/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl(c: Context)(x: c.Tree) = { + def unapplyImpl(c: BlackboxContext)(x: c.Tree) = { import c.universe._ q""" class Match(x: Int) { diff --git a/test/files/neg/t5903e/Macros_1.scala b/test/files/neg/t5903e/Macros_1.scala index 4e1ce89c9f..13e168d529 100644 --- a/test/files/neg/t5903e/Macros_1.scala +++ b/test/files/neg/t5903e/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl(c: Context)(x: c.Tree) = { + def unapplyImpl(c: BlackboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/neg/t6123-explaintypes-macros.check b/test/files/neg/t6123-explaintypes-macros.check index 43f8371326..9a0402039b 100644 --- a/test/files/neg/t6123-explaintypes-macros.check +++ b/test/files/neg/t6123-explaintypes-macros.check @@ -1,9 +1,9 @@ c.universe.Expr[Any]* <: c.universe.Expr[String]*? false BadMac_2.scala:6: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] - or : (c: scala.reflect.macros.Context)(format: c.Tree, params: Tree*): c.Tree - found : (c: scala.reflect.macros.Context)(format: c.Expr[String], params: c.Expr[String]*): c.Expr[Unit] + required: (c: scala.reflect.macros.BlackboxContext)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] + or : (c: scala.reflect.macros.BlackboxContext)(format: c.Tree, params: Tree*): c.Tree + found : (c: scala.reflect.macros.BlackboxContext)(format: c.Expr[String], params: c.Expr[String]*): c.Expr[Unit] type mismatch for parameter params: c.Expr[Any]* does not conform to c.Expr[String]* def printf(format: String, params: Any*): Unit = macro printf_impl ^ diff --git a/test/files/neg/t6123-explaintypes-macros/BadMac_2.scala b/test/files/neg/t6123-explaintypes-macros/BadMac_2.scala index 38b8e24444..456e753893 100644 --- a/test/files/neg/t6123-explaintypes-macros/BadMac_2.scala +++ b/test/files/neg/t6123-explaintypes-macros/BadMac_2.scala @@ -1,8 +1,8 @@ import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext // explain some macro types to me object BadMac { def printf(format: String, params: Any*): Unit = macro printf_impl - def printf_impl(c: Context)(format: c.Expr[String], params: c.Expr[String]*): c.Expr[Unit] = ??? + def printf_impl(c: BlackboxContext)(format: c.Expr[String], params: c.Expr[String]*): c.Expr[Unit] = ??? } diff --git a/test/files/neg/t6123-explaintypes-macros/Macros.scala b/test/files/neg/t6123-explaintypes-macros/Macros.scala index a12c277c86..cdcea34272 100644 --- a/test/files/neg/t6123-explaintypes-macros/Macros.scala +++ b/test/files/neg/t6123-explaintypes-macros/Macros.scala @@ -1,9 +1,9 @@ import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { def printf(format: String, params: Any*): Unit = macro printf_impl - def printf_impl(c: Context)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] = ??? + def printf_impl(c: BlackboxContext)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] = ??? } // something trivial to run diff --git a/test/files/neg/t6539/Macro_1.scala b/test/files/neg/t6539/Macro_1.scala index 4f7d289e2e..454489752c 100644 --- a/test/files/neg/t6539/Macro_1.scala +++ b/test/files/neg/t6539/Macro_1.scala @@ -1,9 +1,9 @@ import language.experimental.macros -import reflect.macros.Context +import reflect.macros.BlackboxContext object M { def m(a: Any, b: Any): Any = macro mImpl - def mImpl(c: Context)(a: c.Expr[Any], b: c.Expr[Any]) = a + def mImpl(c: BlackboxContext)(a: c.Expr[Any], b: c.Expr[Any]) = c.universe.reify(println(a.splice)) @reflect.internal.annotations.compileTimeOnly("cto may only be used as an argument to " + "m") def cto = 0 diff --git a/test/files/neg/t7157/Impls_Macros_1.scala b/test/files/neg/t7157/Impls_Macros_1.scala index 9069d26e6e..16cb001422 100644 --- a/test/files/neg/t7157/Impls_Macros_1.scala +++ b/test/files/neg/t7157/Impls_Macros_1.scala @@ -1,31 +1,31 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Macros { - def impl1_0_0(c: Context)() = { import c.universe._; c.Expr[Unit](q"()") } - def impl1_1_1(c: Context)(x: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } - def impl1_2_2(c: Context)(x: c.Expr[Int], y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } + def impl1_0_0(c: BlackboxContext)() = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl1_1_1(c: BlackboxContext)(x: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl1_2_2(c: BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } def m1_0_0() = macro impl1_0_0 def m1_1_1(x: Int) = macro impl1_1_1 def m1_2_2(x: Int, y: Int) = macro impl1_2_2 - def impl1_0_inf(c: Context)(x: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } - def impl1_1_inf(c: Context)(x: c.Expr[Int], y: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } - def impl1_2_inf(c: Context)(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } + def impl1_0_inf(c: BlackboxContext)(x: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl1_1_inf(c: BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl1_2_inf(c: BlackboxContext)(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } def m1_0_inf(x: Int*) = macro impl1_0_inf def m1_1_inf(x: Int, y: Int*) = macro impl1_1_inf def m1_2_inf(x: Int, y: Int, z: Int*) = macro impl1_2_inf - def impl2_0_0(c: Context)()() = { import c.universe._; c.Expr[Unit](q"()") } - def impl2_1_1(c: Context)()(x: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } - def impl2_2_2(c: Context)()(x: c.Expr[Int], y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } + def impl2_0_0(c: BlackboxContext)()() = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl2_1_1(c: BlackboxContext)()(x: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl2_2_2(c: BlackboxContext)()(x: c.Expr[Int], y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } def m2_0_0()() = macro impl2_0_0 def m2_1_1()(x: Int) = macro impl2_1_1 def m2_2_2()(x: Int, y: Int) = macro impl2_2_2 - def impl2_0_inf(c: Context)()(x: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } - def impl2_1_inf(c: Context)()(x: c.Expr[Int], y: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } - def impl2_2_inf(c: Context)()(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"()") } + def impl2_0_inf(c: BlackboxContext)()(x: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl2_1_inf(c: BlackboxContext)()(x: c.Expr[Int], y: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl2_2_inf(c: BlackboxContext)()(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } def m2_0_inf()(x: Int*) = macro impl2_0_inf def m2_1_inf()(x: Int, y: Int*) = macro impl2_1_inf def m2_2_inf()(x: Int, y: Int, z: Int*) = macro impl2_2_inf diff --git a/test/files/pos/annotated-original/M_1.scala b/test/files/pos/annotated-original/M_1.scala index 01654e02cf..089a3a13c5 100644 --- a/test/files/pos/annotated-original/M_1.scala +++ b/test/files/pos/annotated-original/M_1.scala @@ -1,7 +1,7 @@ import language.experimental.macros -import reflect.macros.Context +import reflect.macros.BlackboxContext object M { - def impl(c: Context)(a: c.Expr[Any]) = c.Expr[Any](c.resetLocalAttrs(a.tree)) + def impl(c: BlackboxContext)(a: c.Expr[Any]) = c.Expr[Any](c.resetLocalAttrs(a.tree)) def m(a: Any) = macro impl } diff --git a/test/files/pos/annotated-treecopy/Impls_Macros_1.scala b/test/files/pos/annotated-treecopy/Impls_Macros_1.scala index 9b7af0c3b8..50c671707d 100644 --- a/test/files/pos/annotated-treecopy/Impls_Macros_1.scala +++ b/test/files/pos/annotated-treecopy/Impls_Macros_1.scala @@ -1,5 +1,5 @@ import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import collection.mutable.ListBuffer import collection.mutable.Stack @@ -12,7 +12,7 @@ object Macros { def tree[T,U](f:Function1[T,U]): Function1[T,U] = macro tree_impl[T,U] - def tree_impl[T:c.WeakTypeTag,U:c.WeakTypeTag](c: Context) + def tree_impl[T:c.WeakTypeTag,U:c.WeakTypeTag](c: BlackboxContext) (f:c.Expr[Function1[T,U]]): c.Expr[Function1[T,U]] = { import c.universe._ val ttag = c.weakTypeTag[U] diff --git a/test/files/pos/attachments-typed-another-ident/Impls_1.scala b/test/files/pos/attachments-typed-another-ident/Impls_1.scala index c3f541075e..f84e56d714 100644 --- a/test/files/pos/attachments-typed-another-ident/Impls_1.scala +++ b/test/files/pos/attachments-typed-another-ident/Impls_1.scala @@ -1,10 +1,10 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object MyAttachment object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ val ident = Ident(TermName("bar")) updateAttachment MyAttachment assert(ident.attachments.get[MyAttachment.type].isDefined, ident.attachments) diff --git a/test/files/pos/attachments-typed-ident/Impls_1.scala b/test/files/pos/attachments-typed-ident/Impls_1.scala index c382cabc59..11d0f65844 100644 --- a/test/files/pos/attachments-typed-ident/Impls_1.scala +++ b/test/files/pos/attachments-typed-ident/Impls_1.scala @@ -1,10 +1,10 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object MyAttachment object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ val ident = Ident(TermName("bar")) updateAttachment MyAttachment assert(ident.attachments.get[MyAttachment.type].isDefined, ident.attachments) diff --git a/test/files/pos/t5692a/Macros_1.scala b/test/files/pos/t5692a/Macros_1.scala index e530713bb0..0e91f4d6a0 100644 --- a/test/files/pos/t5692a/Macros_1.scala +++ b/test/files/pos/t5692a/Macros_1.scala @@ -1,6 +1,6 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl[T](c: Context) = { import c.universe._; c.Expr[Unit](q"()") } + def impl[T](c: BlackboxContext) = { import c.universe._; c.Expr[Unit](q"()") } def foo[T] = macro impl[T] } \ No newline at end of file diff --git a/test/files/pos/t5692b/Macros_1.scala b/test/files/pos/t5692b/Macros_1.scala index 45c672cfce..1034a1ea4a 100644 --- a/test/files/pos/t5692b/Macros_1.scala +++ b/test/files/pos/t5692b/Macros_1.scala @@ -1,6 +1,6 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl[T, U](c: Context) = { import c.universe._; c.Expr[Unit](q"()") } + def impl[T, U](c: BlackboxContext) = { import c.universe._; c.Expr[Unit](q"()") } def foo[T, U] = macro impl[T, U] } \ No newline at end of file diff --git a/test/files/pos/t5706.scala b/test/files/pos/t5706.scala index 20a8b255cc..1970f5971f 100644 --- a/test/files/pos/t5706.scala +++ b/test/files/pos/t5706.scala @@ -1,10 +1,15 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext class Logger { - def error(message: String) = macro Impls.error + def error1(message: String) = macro Impls.error1 + def error2(message: String) = macro Impls.error2 } object Impls { - type LoggerContext = Context { type PrefixType = Logger } - def error(c: LoggerContext)(message: c.Expr[String]): c.Expr[Unit] = ??? + type LoggerContext1 = BlackboxContext { type PrefixType = Logger } + def error1(c: LoggerContext1)(message: c.Expr[String]): c.Expr[Unit] = ??? + + type LoggerContext2 = WhiteboxContext { type PrefixType = Logger } + def error2(c: LoggerContext2)(message: c.Expr[String]): c.Expr[Unit] = ??? } diff --git a/test/files/pos/t5744/Macros_1.scala b/test/files/pos/t5744/Macros_1.scala index 288a88653d..0fc13c12d7 100644 --- a/test/files/pos/t5744/Macros_1.scala +++ b/test/files/pos/t5744/Macros_1.scala @@ -1,18 +1,18 @@ import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { def foo[U: Numeric](x: U) = macro foo_impl[U] def bar[U: Numeric : Equiv, Y <% String](x: U)(implicit s: String) = macro bar_impl[U, Y] - def foo_impl[U](c: Context)(x: c.Expr[U])(numeric: c.Expr[Numeric[U]]) = { + def foo_impl[U](c: BlackboxContext)(x: c.Expr[U])(numeric: c.Expr[Numeric[U]]) = { import c.universe._ val plusOne = Apply(Select(numeric.tree, newTermName("plus")), List(x.tree, Literal(Constant(1)))) val body = Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(plusOne)) c.Expr[Unit](body) } - def bar_impl[U, Y](c: Context)(x: c.Expr[U])(numeric: c.Expr[Numeric[U]], equiv: c.Expr[Equiv[U]], viewAsString: c.Expr[Y => String], s: c.Expr[String]) = { + def bar_impl[U, Y](c: BlackboxContext)(x: c.Expr[U])(numeric: c.Expr[Numeric[U]], equiv: c.Expr[Equiv[U]], viewAsString: c.Expr[Y => String], s: c.Expr[String]) = { import c.universe._ val plusOne = Apply(Select(numeric.tree, newTermName("plus")), List(x.tree, Literal(Constant(1)))) val plusLen = Apply(Select(numeric.tree, newTermName("plus")), List(plusOne, Select(s.tree, newTermName("length")))) diff --git a/test/files/pos/t6047.scala b/test/files/pos/t6047.scala index bc5f856bd2..c5bb44d87e 100644 --- a/test/files/pos/t6047.scala +++ b/test/files/pos/t6047.scala @@ -1,10 +1,10 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import java.io.InputStream object Macros { def unpack[A](input: InputStream): A = macro unpack_impl[A] - def unpack_impl[A: c.WeakTypeTag](c: Context)(input: c.Expr[InputStream]): c.Expr[A] = { + def unpack_impl[A: c.WeakTypeTag](c: BlackboxContext)(input: c.Expr[InputStream]): c.Expr[A] = { import c.universe._ def unpackcode(tpe: c.Type): c.Expr[_] = { diff --git a/test/files/pos/t6447.scala b/test/files/pos/t6447.scala index 1c0c0f2a31..8203c0cddd 100644 --- a/test/files/pos/t6447.scala +++ b/test/files/pos/t6447.scala @@ -1,18 +1,18 @@ import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext class X { type T } object X { // this works def foo(x: X): x.T = macro fooImpl - def fooImpl(c: Context)(x: c.Expr[X]): c.Expr[x.value.T] = ??? + def fooImpl(c: BlackboxContext)(x: c.Expr[X]): c.Expr[x.value.T] = ??? // this doesn't def bar(x: X, y: X): (x.T, y.T) = macro barImpl - def barImpl(c: Context)(x: c.Expr[X], y: c.Expr[X]): c.Expr[(x.value.T, y.value.T)] = ??? + def barImpl(c: BlackboxContext)(x: c.Expr[X], y: c.Expr[X]): c.Expr[(x.value.T, y.value.T)] = ??? // neither does this def baz(x: X)(xs: List[x.T]): Unit = macro bazImpl - def bazImpl(c: Context)(x: c.Expr[X])(xs: c.Expr[List[x.value.T]]): c.Expr[Unit] = ??? + def bazImpl(c: BlackboxContext)(x: c.Expr[X])(xs: c.Expr[List[x.value.T]]): c.Expr[Unit] = ??? } diff --git a/test/files/pos/t6485a/Macros_1.scala b/test/files/pos/t6485a/Macros_1.scala index 85c2d5dbdb..c637c2cfee 100644 --- a/test/files/pos/t6485a/Macros_1.scala +++ b/test/files/pos/t6485a/Macros_1.scala @@ -1,5 +1,5 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def crash(c: Context): c.Expr[Unit] = c.universe.reify(()) + def crash(c: BlackboxContext): c.Expr[Unit] = c.universe.reify(()) } \ No newline at end of file diff --git a/test/files/pos/t6485b/Test.scala b/test/files/pos/t6485b/Test.scala index 382df1c453..9897987516 100644 --- a/test/files/pos/t6485b/Test.scala +++ b/test/files/pos/t6485b/Test.scala @@ -1,10 +1,10 @@ import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext final class Ops[T](val x: T) extends AnyVal { def f = macro Macros.crash } object Macros { - def crash(c: Context): c.Expr[Unit] = c.universe.reify(()) + def crash(c: BlackboxContext): c.Expr[Unit] = c.universe.reify(()) } \ No newline at end of file diff --git a/test/files/pos/t6516.scala b/test/files/pos/t6516.scala index c004055de2..aed359976e 100644 --- a/test/files/pos/t6516.scala +++ b/test/files/pos/t6516.scala @@ -1,17 +1,17 @@ import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import scala.collection.TraversableLike // This one compiles object Test { - type Alias[T, CC[_]] = Context { type PrefixType = TraversableLike[T, CC[T]] } + type Alias[T, CC[_]] = BlackboxContext { type PrefixType = TraversableLike[T, CC[T]] } def f() = macro f_impl def f_impl(c: Alias[Int, List])() = ??? } // This one doesn't object Test2 { - type Ctx = scala.reflect.macros.Context + type Ctx = scala.reflect.macros.BlackboxContext type Alias[T, CC[_]] = Ctx { type PrefixType = TraversableLike[T, CC[T]] } def f() = macro f_impl diff --git a/test/files/pos/t7377/Macro_1.scala b/test/files/pos/t7377/Macro_1.scala index a0ec1d84af..bb7ffb0f10 100644 --- a/test/files/pos/t7377/Macro_1.scala +++ b/test/files/pos/t7377/Macro_1.scala @@ -1,7 +1,7 @@ import language.experimental._ -import reflect.macros.Context +import reflect.macros.BlackboxContext object M { - def noopImpl[A](c: Context)(expr: c.Expr[A]): c.Expr[A] = c.Expr(c.typeCheck(c.resetLocalAttrs(expr.tree))) + def noopImpl[A](c: BlackboxContext)(expr: c.Expr[A]): c.Expr[A] = c.Expr(c.typeCheck(c.resetLocalAttrs(expr.tree))) def noop[A](expr: A): A = macro noopImpl[A] } diff --git a/test/files/pos/t7461/Macros_1.scala b/test/files/pos/t7461/Macros_1.scala index 8621650f77..126e9c067a 100644 --- a/test/files/pos/t7461/Macros_1.scala +++ b/test/files/pos/t7461/Macros_1.scala @@ -1,8 +1,8 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ val wut = c.typeCheck(Select(Literal(Constant(10)), newTermName("$minus")), silent = true) // println(showRaw(wut, printIds = true, printTypes = true)) diff --git a/test/files/pos/t7649.scala b/test/files/pos/t7649.scala index ff3c626fca..fa5d13369f 100644 --- a/test/files/pos/t7649.scala +++ b/test/files/pos/t7649.scala @@ -1,5 +1,5 @@ object Test { - val c: reflect.macros.Context = ??? + val c: reflect.macros.BlackboxContext = ??? import c.universe._ reify { // The lookup of the implicit WeakTypeTag[Any] diff --git a/test/files/run/macro-abort-fresh/Macros_1.scala b/test/files/run/macro-abort-fresh/Macros_1.scala index 415b76852f..350d7b41aa 100644 --- a/test/files/run/macro-abort-fresh/Macros_1.scala +++ b/test/files/run/macro-abort-fresh/Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Impls { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ println(c.fresh()) println(c.fresh("qwe")) diff --git a/test/files/run/macro-auto-duplicate/Macros_1.scala b/test/files/run/macro-auto-duplicate/Macros_1.scala index e3df05ba50..255dafd47e 100644 --- a/test/files/run/macro-auto-duplicate/Macros_1.scala +++ b/test/files/run/macro-auto-duplicate/Macros_1.scala @@ -1,8 +1,8 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ val x = Ident(newTermName("x")) def defAndUseX(rhs: Tree) = { diff --git a/test/files/run/macro-basic-ma-md-mi/Impls_1.scala b/test/files/run/macro-basic-ma-md-mi/Impls_1.scala index ce30366c61..c63353164e 100644 --- a/test/files/run/macro-basic-ma-md-mi/Impls_1.scala +++ b/test/files/run/macro-basic-ma-md-mi/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { diff --git a/test/files/run/macro-basic-ma-mdmi/Impls_Macros_1.scala b/test/files/run/macro-basic-ma-mdmi/Impls_Macros_1.scala index a601af6dde..3cdd531316 100644 --- a/test/files/run/macro-basic-ma-mdmi/Impls_Macros_1.scala +++ b/test/files/run/macro-basic-ma-mdmi/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { diff --git a/test/files/run/macro-basic-mamd-mi/Impls_1.scala b/test/files/run/macro-basic-mamd-mi/Impls_1.scala index 6e5983bdec..3feddd2786 100644 --- a/test/files/run/macro-basic-mamd-mi/Impls_1.scala +++ b/test/files/run/macro-basic-mamd-mi/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]): c.Expr[Int] = { diff --git a/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala b/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala index 56c5252f31..9af3b18ccb 100644 --- a/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala +++ b/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala @@ -1,10 +1,11 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.language.experimental.macros +import scala.reflect.macros.BlackboxContext object Impls { - def foo(c: Ctx)(x: c.Expr[Int]) = x + def foo(c: BlackboxContext)(x: c.Expr[Int]) = x def refToFoo(dummy: Int) = macro refToFoo_impl - def refToFoo_impl(c: Ctx)(dummy: c.Expr[Int]) = { + def refToFoo_impl(c: BlackboxContext)(dummy: c.Expr[Int]) = { import c.universe._ val body = Select(Ident(TermName("Impls")), TermName("foo")) val global = c.universe.asInstanceOf[scala.tools.nsc.Global] diff --git a/test/files/run/macro-bodyexpandstoimpl/Macros_Test_2.scala b/test/files/run/macro-bodyexpandstoimpl/Macros_Test_2.scala index b589d4be03..cfcb59c17b 100644 --- a/test/files/run/macro-bodyexpandstoimpl/Macros_Test_2.scala +++ b/test/files/run/macro-bodyexpandstoimpl/Macros_Test_2.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.language.experimental.macros object Macros { def foo(x: Int) = macro Impls.refToFoo(42) diff --git a/test/files/run/macro-bundle-repl.check b/test/files/run/macro-bundle-repl.check index c11c48dc55..795debded7 100644 --- a/test/files/run/macro-bundle-repl.check +++ b/test/files/run/macro-bundle-repl.check @@ -4,16 +4,16 @@ Type :help for more information. scala> import scala.language.experimental.macros import scala.language.experimental.macros -scala> import scala.reflect.macros.Macro -import scala.reflect.macros.Macro +scala> import scala.reflect.macros.BlackboxMacro +import scala.reflect.macros.BlackboxMacro -scala> trait Bar extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar = macro Bar.impl +scala> trait Bar extends BlackboxMacro { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar = macro Bar.impl defined trait Bar defined term macro bar: Unit scala> bar -scala> trait Foo extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } } +scala> trait Foo extends BlackboxMacro { def impl = { import c.universe._; c.Expr[Unit](q"()") } } defined trait Foo scala> def foo = macro Foo.impl diff --git a/test/files/run/macro-bundle-repl.scala b/test/files/run/macro-bundle-repl.scala index 3171aaacc2..50811cdb65 100644 --- a/test/files/run/macro-bundle-repl.scala +++ b/test/files/run/macro-bundle-repl.scala @@ -3,11 +3,11 @@ import scala.tools.partest.ReplTest object Test extends ReplTest { def code = """ import scala.language.experimental.macros -import scala.reflect.macros.Macro -trait Bar extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar = macro Bar.impl +import scala.reflect.macros.BlackboxMacro +trait Bar extends BlackboxMacro { def impl = { import c.universe._; c.Expr[Unit](q"()") } };def bar = macro Bar.impl bar -trait Foo extends Macro { def impl = { import c.universe._; c.Expr[Unit](q"()") } } +trait Foo extends BlackboxMacro { def impl = { import c.universe._; c.Expr[Unit](q"()") } } def foo = macro Foo.impl foo """ -} \ No newline at end of file +} diff --git a/test/files/run/macro-bundle-static/Impls_Macros_1.scala b/test/files/run/macro-bundle-static/Impls_Macros_1.scala index e81fd0dbd6..b859411325 100644 --- a/test/files/run/macro-bundle-static/Impls_Macros_1.scala +++ b/test/files/run/macro-bundle-static/Impls_Macros_1.scala @@ -1,9 +1,8 @@ -import scala.reflect.macros.Context -import scala.reflect.macros.Macro +import scala.reflect.macros.BlackboxMacro import scala.language.experimental.macros object Enclosing { - trait Impl extends Macro { + trait Impl extends BlackboxMacro { def mono = { import c.universe._; c.Expr[Unit](q"()") } def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString}") } def weird = macro mono @@ -17,7 +16,7 @@ object Macros { package pkg { object Enclosing { - trait Impl extends Macro { + trait Impl extends BlackboxMacro { def mono = { import c.universe._; c.Expr[Boolean](q"true") } def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString + c.weakTypeOf[T].toString}") } def weird = macro mono diff --git a/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala b/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala index 8c7df2cdc5..e026768642 100644 --- a/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala +++ b/test/files/run/macro-bundle-toplevel/Impls_Macros_1.scala @@ -1,7 +1,6 @@ -import scala.reflect.macros.Context -import scala.reflect.macros.Macro +import scala.reflect.macros.BlackboxMacro -trait Impl extends Macro { +trait Impl extends BlackboxMacro { def mono = { import c.universe._; c.Expr[Unit](q"()") } def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString}") } def weird = macro mono @@ -13,7 +12,7 @@ object Macros { } package pkg { - trait Impl extends Macro { + trait Impl extends BlackboxMacro { def mono = { import c.universe._; c.Expr[Boolean](q"true") } def poly[T: c.WeakTypeTag] = { import c.universe._; c.Expr[String](q"${c.weakTypeOf[T].toString + c.weakTypeOf[T].toString}") } def weird = macro mono diff --git a/test/files/run/macro-def-infer-return-type/Impls_1.scala b/test/files/run/macro-def-infer-return-type/Impls_1.scala index f8636fe725..c670b1e57e 100644 --- a/test/files/run/macro-def-infer-return-type/Impls_1.scala +++ b/test/files/run/macro-def-infer-return-type/Impls_1.scala @@ -1,14 +1,14 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Impls1 { - def foo(c: Context)(x: c.Expr[Int]) = x + def foo(c: BlackboxContext)(x: c.Expr[Int]) = x } object Impls2 { - def foo[T](c: Context)(x: c.Expr[T]) = + def foo[T](c: BlackboxContext)(x: c.Expr[T]) = throw new Error("an implementation is missing") } object Impls3 { - def foo[T](c: Context)(x: c.Expr[T]): c.Expr[T] = x + def foo[T](c: BlackboxContext)(x: c.Expr[T]): c.Expr[T] = x } diff --git a/test/files/run/macro-def-path-dependent/Test_1.scala b/test/files/run/macro-def-path-dependent/Test_1.scala index 06c15e16c9..f9aa13c334 100644 --- a/test/files/run/macro-def-path-dependent/Test_1.scala +++ b/test/files/run/macro-def-path-dependent/Test_1.scala @@ -1,6 +1,6 @@ package test1 -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} trait Exprs { self: Universe => diff --git a/test/files/run/macro-def-path-dependent/Test_2.scala b/test/files/run/macro-def-path-dependent/Test_2.scala index f1e9909981..cdedaf2732 100644 --- a/test/files/run/macro-def-path-dependent/Test_2.scala +++ b/test/files/run/macro-def-path-dependent/Test_2.scala @@ -1,6 +1,6 @@ package test2 -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} trait Exprs { self: Universe => diff --git a/test/files/run/macro-def-path-dependent/Test_3.scala b/test/files/run/macro-def-path-dependent/Test_3.scala index 9f5efe5e47..6d856d1450 100644 --- a/test/files/run/macro-def-path-dependent/Test_3.scala +++ b/test/files/run/macro-def-path-dependent/Test_3.scala @@ -1,6 +1,6 @@ package test3 -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} trait Exprs { self: Universe => diff --git a/test/files/run/macro-def-path-dependent/Test_4.scala b/test/files/run/macro-def-path-dependent/Test_4.scala index 3af920d739..e8a8cf3909 100644 --- a/test/files/run/macro-def-path-dependent/Test_4.scala +++ b/test/files/run/macro-def-path-dependent/Test_4.scala @@ -1,11 +1,11 @@ package test4 import scala.reflect.runtime.universe._ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import scala.reflect.api.Universe object Test { def materializeTypeTag[T](u: Universe)(e: T) = macro materializeTypeTag_impl[T] - def materializeTypeTag_impl[T: c.WeakTypeTag](c: Context)(u: c.Expr[Universe])(e: c.Expr[T]): c.Expr[u.value.TypeTag[T]] = ??? + def materializeTypeTag_impl[T: c.WeakTypeTag](c: BlackboxContext)(u: c.Expr[Universe])(e: c.Expr[T]): c.Expr[u.value.TypeTag[T]] = ??? } \ No newline at end of file diff --git a/test/files/run/macro-def-path-dependent/Test_5.scala b/test/files/run/macro-def-path-dependent/Test_5.scala index bc32fb92de..22407b850c 100644 --- a/test/files/run/macro-def-path-dependent/Test_5.scala +++ b/test/files/run/macro-def-path-dependent/Test_5.scala @@ -1,9 +1,9 @@ package test56 import scala.reflect.runtime.universe._ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import scala.reflect.api.Universe object Impls { - def materializeTypeTag_impl[T: c.WeakTypeTag](c: Context)(u: c.Expr[Universe])(e: c.Expr[T]): c.Expr[u.value.TypeTag[T]] = ??? + def materializeTypeTag_impl[T: c.WeakTypeTag](c: BlackboxContext)(u: c.Expr[Universe])(e: c.Expr[T]): c.Expr[u.value.TypeTag[T]] = ??? } \ No newline at end of file diff --git a/test/files/run/macro-def-path-dependent/Test_6.scala b/test/files/run/macro-def-path-dependent/Test_6.scala index 6267743473..c8ddffc143 100644 --- a/test/files/run/macro-def-path-dependent/Test_6.scala +++ b/test/files/run/macro-def-path-dependent/Test_6.scala @@ -1,7 +1,7 @@ package test56 import scala.reflect.runtime.universe._ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import scala.reflect.api.Universe object Macros { diff --git a/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala b/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala index 53511ebc72..4bafa84128 100644 --- a/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala +++ b/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros trait Complex[T] @@ -7,7 +7,7 @@ class Foo(val bar: Bar) class Bar(val s: String) object Complex { - def impl[T: c.WeakTypeTag](c: Context): c.Expr[Complex[T]] = { + def impl[T: c.WeakTypeTag](c: BlackboxContext): c.Expr[Complex[T]] = { import c.universe._ val tpe = weakTypeOf[T] for (f <- tpe.declarations.collect{case f: TermSymbol if f.isParamAccessor && !f.isMethod => f}) { diff --git a/test/files/run/macro-duplicate/Impls_Macros_1.scala b/test/files/run/macro-duplicate/Impls_Macros_1.scala index 85a581585f..e9bcaf5d8d 100644 --- a/test/files/run/macro-duplicate/Impls_Macros_1.scala +++ b/test/files/run/macro-duplicate/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ val Expr(Block((cdef: ClassDef) :: Nil, _)) = reify { class C { def x = 2 } } val cdef1 = diff --git a/test/files/run/macro-enclosures/Impls_Macros_1.scala b/test/files/run/macro-enclosures/Impls_Macros_1.scala index 68f1920cdd..dfffb48e73 100644 --- a/test/files/run/macro-enclosures/Impls_Macros_1.scala +++ b/test/files/run/macro-enclosures/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ reify { println("enclosingPackage = " + c.Expr[String](Literal(Constant(c.enclosingPackage.toString))).splice) diff --git a/test/files/run/macro-expand-implicit-argument/Macros_1.scala b/test/files/run/macro-expand-implicit-argument/Macros_1.scala index b2c7b4d6ca..7ac30e3ff2 100644 --- a/test/files/run/macro-expand-implicit-argument/Macros_1.scala +++ b/test/files/run/macro-expand-implicit-argument/Macros_1.scala @@ -5,7 +5,7 @@ import scala.{specialized => spec} import language.experimental.macros import scala.reflect.ClassTag -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { def alloc[@spec A:ClassTag](src:Array[A], s1:Int, len:Int) = { @@ -35,7 +35,7 @@ object Macros { * arr * } */ - def arrayMacro[A:c.WeakTypeTag](c:Context)(as:c.Expr[A]*)(ct: c.Expr[ClassTag[A]]): c.Expr[Array[A]] = { + def arrayMacro[A:c.WeakTypeTag](c:BlackboxContext)(as:c.Expr[A]*)(ct: c.Expr[ClassTag[A]]): c.Expr[Array[A]] = { import c.mirror._ import c.universe._ def const(x:Int) = Literal(Constant(x)) diff --git a/test/files/run/macro-expand-implicit-macro-has-implicit/Impls_1.scala b/test/files/run/macro-expand-implicit-macro-has-implicit/Impls_1.scala index ac1e55c9b2..c56489e61c 100644 --- a/test/files/run/macro-expand-implicit-macro-has-implicit/Impls_1.scala +++ b/test/files/run/macro-expand-implicit-macro-has-implicit/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = { diff --git a/test/files/run/macro-expand-implicit-macro-is-implicit/Impls_1.scala b/test/files/run/macro-expand-implicit-macro-is-implicit/Impls_1.scala index aa1fc7a358..f93d9100e8 100644 --- a/test/files/run/macro-expand-implicit-macro-is-implicit/Impls_1.scala +++ b/test/files/run/macro-expand-implicit-macro-is-implicit/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[String]): c.Expr[Option[Int]] = { diff --git a/test/files/run/macro-expand-implicit-macro-is-val/Impls_1.scala b/test/files/run/macro-expand-implicit-macro-is-val/Impls_1.scala index fa717b2327..a8b478e9f2 100644 --- a/test/files/run/macro-expand-implicit-macro-is-val/Impls_1.scala +++ b/test/files/run/macro-expand-implicit-macro-is-val/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-expand-implicit-macro-is-view/Impls_1.scala b/test/files/run/macro-expand-implicit-macro-is-view/Impls_1.scala index aa1fc7a358..f93d9100e8 100644 --- a/test/files/run/macro-expand-implicit-macro-is-view/Impls_1.scala +++ b/test/files/run/macro-expand-implicit-macro-is-view/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[String]): c.Expr[Option[Int]] = { diff --git a/test/files/run/macro-expand-multiple-arglists/Impls_1.scala b/test/files/run/macro-expand-multiple-arglists/Impls_1.scala index 4fddc13d68..bc3d768a67 100644 --- a/test/files/run/macro-expand-multiple-arglists/Impls_1.scala +++ b/test/files/run/macro-expand-multiple-arglists/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int])(y: c.Expr[Int]) = { diff --git a/test/files/run/macro-expand-nullary-generic/Impls_1.scala b/test/files/run/macro-expand-nullary-generic/Impls_1.scala index 5dfdd5c539..e0a048046f 100644 --- a/test/files/run/macro-expand-nullary-generic/Impls_1.scala +++ b/test/files/run/macro-expand-nullary-generic/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def impl[T: c.WeakTypeTag](c: Ctx)(meth: String) = { diff --git a/test/files/run/macro-expand-nullary-nongeneric/Impls_1.scala b/test/files/run/macro-expand-nullary-nongeneric/Impls_1.scala index d23c671c84..5da33babd3 100644 --- a/test/files/run/macro-expand-nullary-nongeneric/Impls_1.scala +++ b/test/files/run/macro-expand-nullary-nongeneric/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def impl(c: Ctx)(meth: String) = { diff --git a/test/files/run/macro-expand-overload/Impls_1.scala b/test/files/run/macro-expand-overload/Impls_1.scala index 1c672f6040..ea68e9eb93 100644 --- a/test/files/run/macro-expand-overload/Impls_1.scala +++ b/test/files/run/macro-expand-overload/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def impl(c: Ctx)(tag: String, x: c.Expr[_]) = { diff --git a/test/files/run/macro-expand-override/Impls_1.scala b/test/files/run/macro-expand-override/Impls_1.scala index 69ef57d18d..648641f578 100644 --- a/test/files/run/macro-expand-override/Impls_1.scala +++ b/test/files/run/macro-expand-override/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def impl(c: Ctx)(tag: String, x: c.Expr[_]) = { diff --git a/test/files/run/macro-expand-recursive/Impls_1.scala b/test/files/run/macro-expand-recursive/Impls_1.scala index 47dd398454..8ba1a24540 100644 --- a/test/files/run/macro-expand-recursive/Impls_1.scala +++ b/test/files/run/macro-expand-recursive/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-expand-tparams-bounds.check b/test/files/run/macro-expand-tparams-bounds.check new file mode 100644 index 0000000000..317e9677c3 --- /dev/null +++ b/test/files/run/macro-expand-tparams-bounds.check @@ -0,0 +1,2 @@ +hello +hello diff --git a/test/files/run/macro-expand-tparams-bounds/Impls_1.scala b/test/files/run/macro-expand-tparams-bounds/Impls_1.scala index d63f034e9b..a255072774 100644 --- a/test/files/run/macro-expand-tparams-bounds/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-bounds/Impls_1.scala @@ -1,12 +1,12 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Impls1 { - def foo[U <: String](c: Context): c.Expr[Unit] = { import c.universe._; c.Expr[Unit](q"()") } + def foo[U <: String](c: BlackboxContext): c.Expr[Unit] = { import c.universe._; c.Expr[Unit](q"""println("hello")""") } } class C class D extends C object Impls2 { - def foo[U <: C](c: Context): c.Expr[Unit] = { import c.universe._; c.Expr[Unit](q"()") } + def foo[U <: C](c: BlackboxContext): c.Expr[Unit] = { import c.universe._; c.Expr[Unit](q"""println("hello")""") } } diff --git a/test/files/run/macro-expand-tparams-explicit/Impls_1.scala b/test/files/run/macro-expand-tparams-explicit/Impls_1.scala index f748ab855f..e95d61a36a 100644 --- a/test/files/run/macro-expand-tparams-explicit/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-explicit/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo[U: c.WeakTypeTag](c: Ctx) = { diff --git a/test/files/run/macro-expand-tparams-implicit/Impls_1.scala b/test/files/run/macro-expand-tparams-implicit/Impls_1.scala index c729aada51..37cf785c0d 100644 --- a/test/files/run/macro-expand-tparams-implicit/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-implicit/Impls_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo[U: c.WeakTypeTag](c: Ctx)(x: c.Expr[U]) = { diff --git a/test/files/run/macro-expand-tparams-prefix/Impls_1.scala b/test/files/run/macro-expand-tparams-prefix/Impls_1.scala index a98c4abe78..8f85ffff4a 100644 --- a/test/files/run/macro-expand-tparams-prefix/Impls_1.scala +++ b/test/files/run/macro-expand-tparams-prefix/Impls_1.scala @@ -1,8 +1,8 @@ import scala.reflect.runtime.universe._ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Impls1 { - def foo[U: c.WeakTypeTag](c: Context)(x: c.Expr[U]) = { + def foo[U: c.WeakTypeTag](c: BlackboxContext)(x: c.Expr[U]) = { import c.universe._ val U = implicitly[c.WeakTypeTag[U]] c.Expr[Unit](q"println(${U.toString})") @@ -10,7 +10,7 @@ object Impls1 { } object Impls2 { - def foo[T: c.WeakTypeTag, U: c.WeakTypeTag](c: Context)(x: c.Expr[U]) = { + def foo[T: c.WeakTypeTag, U: c.WeakTypeTag](c: BlackboxContext)(x: c.Expr[U]) = { import c.universe._ val T = implicitly[c.WeakTypeTag[T]] val U = implicitly[c.WeakTypeTag[U]] @@ -20,7 +20,7 @@ object Impls2 { } object Impls345 { - def foo[T, U: c.WeakTypeTag, V](c: Context)(implicit T: c.WeakTypeTag[T], V: c.WeakTypeTag[V]): c.Expr[Unit] = { + def foo[T, U: c.WeakTypeTag, V](c: BlackboxContext)(implicit T: c.WeakTypeTag[T], V: c.WeakTypeTag[V]): c.Expr[Unit] = { import c.universe._ c.Expr(q""" println(${T.toString}) diff --git a/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala b/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala index 61d6345f16..b837ffc43b 100644 --- a/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala +++ b/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala @@ -1,11 +1,11 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Helper { def unapplySeq[T](x: List[T]): Option[Seq[T]] = List.unapplySeq[T](x) } object Macros { - def impl[T: c.WeakTypeTag](c: Context)(x: c.Expr[List[T]]) = { + def impl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Expr[List[T]]) = { c.universe.reify(Helper.unapplySeq(x.splice)) } diff --git a/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-bad/Impls_1.scala b/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-bad/Impls_1.scala index f6c1d27d54..2480af61ad 100644 --- a/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-bad/Impls_1.scala +++ b/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-bad/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(xs: c.Expr[Int]*) = { diff --git a/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-good/Impls_1.scala b/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-good/Impls_1.scala index 363ff0e0aa..a31c92a01c 100644 --- a/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-good/Impls_1.scala +++ b/test/files/run/macro-expand-varargs-explicit-over-nonvarargs-good/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(xs: c.Expr[Int]*) = { diff --git a/test/files/run/macro-expand-varargs-explicit-over-varargs/Impls_1.scala b/test/files/run/macro-expand-varargs-explicit-over-varargs/Impls_1.scala index 0b61ab2f9b..889240d628 100644 --- a/test/files/run/macro-expand-varargs-explicit-over-varargs/Impls_1.scala +++ b/test/files/run/macro-expand-varargs-explicit-over-varargs/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def myprintln(xs: Int*) = { diff --git a/test/files/run/macro-expand-varargs-implicit-over-nonvarargs/Impls_1.scala b/test/files/run/macro-expand-varargs-implicit-over-nonvarargs/Impls_1.scala index f6c1d27d54..2480af61ad 100644 --- a/test/files/run/macro-expand-varargs-implicit-over-nonvarargs/Impls_1.scala +++ b/test/files/run/macro-expand-varargs-implicit-over-nonvarargs/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(xs: c.Expr[Int]*) = { diff --git a/test/files/run/macro-expand-varargs-implicit-over-varargs/Impls_1.scala b/test/files/run/macro-expand-varargs-implicit-over-varargs/Impls_1.scala index 0b61ab2f9b..889240d628 100644 --- a/test/files/run/macro-expand-varargs-implicit-over-varargs/Impls_1.scala +++ b/test/files/run/macro-expand-varargs-implicit-over-varargs/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def myprintln(xs: Int*) = { diff --git a/test/files/run/macro-impl-default-params/Impls_Macros_1.scala b/test/files/run/macro-impl-default-params/Impls_Macros_1.scala index 043675ec00..aa76a410ea 100644 --- a/test/files/run/macro-impl-default-params/Impls_Macros_1.scala +++ b/test/files/run/macro-impl-default-params/Impls_Macros_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo_targs[T, U: c.WeakTypeTag](c: Ctx = null)(x: c.Expr[Int] = null) = { diff --git a/test/files/run/macro-impl-relaxed/Macros_1.scala b/test/files/run/macro-impl-relaxed/Macros_1.scala index af62646b4e..3cf5090ec8 100644 --- a/test/files/run/macro-impl-relaxed/Macros_1.scala +++ b/test/files/run/macro-impl-relaxed/Macros_1.scala @@ -1,11 +1,11 @@ import language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def implUU(c: Context)(x: c.Tree): c.Tree = x - def implTU(c: Context)(x: c.Expr[Int]): c.Tree = x.tree - def implUT(c: Context)(x: c.Tree): c.Expr[Int] = c.Expr[Int](x) - def implTT(c: Context)(x: c.Expr[Int]): c.Expr[Int] = x + def implUU(c: BlackboxContext)(x: c.Tree): c.Tree = x + def implTU(c: BlackboxContext)(x: c.Expr[Int]): c.Tree = x.tree + def implUT(c: BlackboxContext)(x: c.Tree): c.Expr[Int] = c.Expr[Int](x) + def implTT(c: BlackboxContext)(x: c.Expr[Int]): c.Expr[Int] = x def fooUU(x: Int): Int = macro implUU def fooTU(x: Int): Int = macro implTU diff --git a/test/files/run/macro-impl-rename-context/Impls_Macros_1.scala b/test/files/run/macro-impl-rename-context/Impls_Macros_1.scala index 5f3bbac719..c79fc30628 100644 --- a/test/files/run/macro-impl-rename-context/Impls_Macros_1.scala +++ b/test/files/run/macro-impl-rename-context/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(unconventionalName: Ctx)(x: unconventionalName.Expr[Int]) = { diff --git a/test/files/run/macro-impl-tparam-only-in-impl.check b/test/files/run/macro-impl-tparam-only-in-impl.check new file mode 100644 index 0000000000..3b18e512db --- /dev/null +++ b/test/files/run/macro-impl-tparam-only-in-impl.check @@ -0,0 +1 @@ +hello world diff --git a/test/files/run/macro-impl-tparam-only-in-impl/Impls_1.scala b/test/files/run/macro-impl-tparam-only-in-impl/Impls_1.scala index 24eacb36de..55cf0dcafa 100644 --- a/test/files/run/macro-impl-tparam-only-in-impl/Impls_1.scala +++ b/test/files/run/macro-impl-tparam-only-in-impl/Impls_1.scala @@ -1,5 +1,5 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { - def foo[U <: String](c: Ctx): c.Expr[Unit] = { import c.universe._; c.Expr[Unit](q"()") } + def foo[U <: String](c: Ctx): c.Expr[Unit] = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } } diff --git a/test/files/run/macro-impl-tparam-typetag-is-optional/Impls_1.scala b/test/files/run/macro-impl-tparam-typetag-is-optional/Impls_1.scala index ace7a6cd26..bcc746e39a 100644 --- a/test/files/run/macro-impl-tparam-typetag-is-optional/Impls_1.scala +++ b/test/files/run/macro-impl-tparam-typetag-is-optional/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo[U](c: Ctx) = { diff --git a/test/files/run/macro-invalidret-doesnt-conform-to-def-rettype/Impls_Macros_1.scala b/test/files/run/macro-invalidret-doesnt-conform-to-def-rettype/Impls_Macros_1.scala index b3babd8848..5a51d27b24 100644 --- a/test/files/run/macro-invalidret-doesnt-conform-to-def-rettype/Impls_Macros_1.scala +++ b/test/files/run/macro-invalidret-doesnt-conform-to-def-rettype/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx): c.Expr[Int] = { diff --git a/test/files/run/macro-invalidret-nontypeable/Impls_Macros_1.scala b/test/files/run/macro-invalidret-nontypeable/Impls_Macros_1.scala index 869a5a41fa..44e508a1c6 100644 --- a/test/files/run/macro-invalidret-nontypeable/Impls_Macros_1.scala +++ b/test/files/run/macro-invalidret-nontypeable/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-invalidusage-badret/Impls_Macros_1.scala b/test/files/run/macro-invalidusage-badret/Impls_Macros_1.scala index 0d840eed3f..a54eaa4001 100644 --- a/test/files/run/macro-invalidusage-badret/Impls_Macros_1.scala +++ b/test/files/run/macro-invalidusage-badret/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = x diff --git a/test/files/run/macro-invalidusage-partialapplication-with-tparams/Impls_Macros_1.scala b/test/files/run/macro-invalidusage-partialapplication-with-tparams/Impls_Macros_1.scala index 8a93161af5..a67a296335 100644 --- a/test/files/run/macro-invalidusage-partialapplication-with-tparams/Impls_Macros_1.scala +++ b/test/files/run/macro-invalidusage-partialapplication-with-tparams/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo[T: c.WeakTypeTag](c: Ctx)(x: c.Expr[T]) = { diff --git a/test/files/run/macro-invalidusage-partialapplication/Impls_Macros_1.scala b/test/files/run/macro-invalidusage-partialapplication/Impls_Macros_1.scala index 3ac9cd2a8d..88929df27a 100644 --- a/test/files/run/macro-invalidusage-partialapplication/Impls_Macros_1.scala +++ b/test/files/run/macro-invalidusage-partialapplication/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int])(y: c.Expr[Int]) = { diff --git a/test/files/run/macro-openmacros/Impls_Macros_1.scala b/test/files/run/macro-openmacros/Impls_Macros_1.scala index 884d7f8825..22e94f32cd 100644 --- a/test/files/run/macro-openmacros/Impls_Macros_1.scala +++ b/test/files/run/macro-openmacros/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c: Context): c.Expr[Unit] = { + def impl(c: BlackboxContext): c.Expr[Unit] = { // we're macros, so we can reflect against our source path // so we don't need any partests to clean up after us! val dir = c.enclosingUnit.source.file.file.getCanonicalFile.getParentFile diff --git a/test/files/run/macro-parse-position/Impls_Macros_1.scala b/test/files/run/macro-parse-position/Impls_Macros_1.scala index b6f1ebbcd5..92f64a8e70 100644 --- a/test/files/run/macro-parse-position/Impls_Macros_1.scala +++ b/test/files/run/macro-parse-position/Impls_Macros_1.scala @@ -1,5 +1,5 @@ import scala.language.experimental.macros -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Macros { def impl(c: Ctx)() = { diff --git a/test/files/run/macro-quasiinvalidbody-c/Impls_Macros_1.scala b/test/files/run/macro-quasiinvalidbody-c/Impls_Macros_1.scala index 6c14428437..04aa11b8fe 100644 --- a/test/files/run/macro-quasiinvalidbody-c/Impls_Macros_1.scala +++ b/test/files/run/macro-quasiinvalidbody-c/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Macros { object Impls { diff --git a/test/files/run/macro-quasiquotes/Macros_1.scala b/test/files/run/macro-quasiquotes/Macros_1.scala index b64eec8743..c42baafdf4 100644 --- a/test/files/run/macro-quasiquotes/Macros_1.scala +++ b/test/files/run/macro-quasiquotes/Macros_1.scala @@ -1,7 +1,7 @@ import language.experimental.macros -import scala.reflect.macros.Macro +import scala.reflect.macros.BlackboxMacro -trait Impls extends Macro { +trait Impls extends BlackboxMacro { import c.universe._ def impl1 = q"println(1)" def impl2 = q"{ println(2); println(3) }" diff --git a/test/files/run/macro-range/Common_1.scala b/test/files/run/macro-range/Common_1.scala index 4083e6126e..1ad2a6c6eb 100644 --- a/test/files/run/macro-range/Common_1.scala +++ b/test/files/run/macro-range/Common_1.scala @@ -1,4 +1,4 @@ -import reflect.macros.Context +import reflect.macros.BlackboxContext abstract class RangeDefault { val from, to: Int @@ -10,7 +10,7 @@ abstract class RangeDefault { /** This class should go into reflect.macro once it is a bit more stable. */ abstract class Utils { - val context: Context + val context: BlackboxContext import context.universe._ class TreeSubstituter(from: List[Symbol], to: List[Tree]) extends Transformer { diff --git a/test/files/run/macro-range/Expansion_Impossible_2.scala b/test/files/run/macro-range/Expansion_Impossible_2.scala index ca0db48822..fa869a2569 100644 --- a/test/files/run/macro-range/Expansion_Impossible_2.scala +++ b/test/files/run/macro-range/Expansion_Impossible_2.scala @@ -1,7 +1,7 @@ -import reflect.macros.Context +import reflect.macros.BlackboxContext object Impls { - def foreach(c: Context)(f: c.Expr[Int => Unit]): c.Expr[Unit] = { + def foreach(c: BlackboxContext)(f: c.Expr[Int => Unit]): c.Expr[Unit] = { // todo. read the compiler config and print if -Ydebug is set //println("macro-expand, _this = "+ _this) object utils extends Utils { val context: c.type = c } diff --git a/test/files/run/macro-reflective-ma-normal-mdmi/Impls_Macros_1.scala b/test/files/run/macro-reflective-ma-normal-mdmi/Impls_Macros_1.scala index 51e0264ed5..53b96691e9 100644 --- a/test/files/run/macro-reflective-ma-normal-mdmi/Impls_Macros_1.scala +++ b/test/files/run/macro-reflective-ma-normal-mdmi/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = { diff --git a/test/files/run/macro-reflective-mamd-normal-mi/Impls_1.scala b/test/files/run/macro-reflective-mamd-normal-mi/Impls_1.scala index 4261a6d45d..81ad5cae0b 100644 --- a/test/files/run/macro-reflective-mamd-normal-mi/Impls_1.scala +++ b/test/files/run/macro-reflective-mamd-normal-mi/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = { diff --git a/test/files/run/macro-reify-basic/Macros_1.scala b/test/files/run/macro-reify-basic/Macros_1.scala index 3f6720f10a..e1a6d8abfb 100644 --- a/test/files/run/macro-reify-basic/Macros_1.scala +++ b/test/files/run/macro-reify-basic/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Macros { def foo(s: String) = macro Impls.foo diff --git a/test/files/run/macro-reify-freevars/Macros_1.scala b/test/files/run/macro-reify-freevars/Macros_1.scala index 20f80c06d1..2cd94f600a 100644 --- a/test/files/run/macro-reify-freevars/Macros_1.scala +++ b/test/files/run/macro-reify-freevars/Macros_1.scala @@ -2,7 +2,7 @@ package scala.collection.slick object QueryableMacros{ def map[T:c.WeakTypeTag, S:c.WeakTypeTag] - (c: scala.reflect.macros.Context) + (c: scala.reflect.macros.BlackboxContext) (projection: c.Expr[T => S]) : c.Expr[scala.collection.slick.Queryable[S]] = { import c.universe._ diff --git a/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala index bb6a45e11e..ebd80c02ba 100644 --- a/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala +++ b/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala @@ -1,8 +1,8 @@ import scala.reflect.runtime.universe._ import scala.reflect.runtime.{universe => ru} -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext -case class Utils[C <: Context]( c:C ) { +case class Utils[C <: BlackboxContext]( c:C ) { import c.universe._ import c.{Tree=>_} object removeDoubleReify extends c.universe.Transformer { @@ -21,7 +21,7 @@ case class Utils[C <: Context]( c:C ) { } } object QueryableMacros{ - def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { + def _helper[C <: BlackboxContext,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { import c.universe._ import treeBuild._ val element_type = implicitly[c.WeakTypeTag[S]].tpe @@ -34,7 +34,7 @@ object QueryableMacros{ c.universe.reify{ Queryable.factory[S]( foo.splice )} } def map[T:c.WeakTypeTag, S:c.WeakTypeTag] - (c: scala.reflect.macros.Context) + (c: scala.reflect.macros.BlackboxContext) (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) } class Queryable[T]{ diff --git a/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala index bb6a45e11e..ebd80c02ba 100644 --- a/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala +++ b/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala @@ -1,8 +1,8 @@ import scala.reflect.runtime.universe._ import scala.reflect.runtime.{universe => ru} -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext -case class Utils[C <: Context]( c:C ) { +case class Utils[C <: BlackboxContext]( c:C ) { import c.universe._ import c.{Tree=>_} object removeDoubleReify extends c.universe.Transformer { @@ -21,7 +21,7 @@ case class Utils[C <: Context]( c:C ) { } } object QueryableMacros{ - def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { + def _helper[C <: BlackboxContext,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { import c.universe._ import treeBuild._ val element_type = implicitly[c.WeakTypeTag[S]].tpe @@ -34,7 +34,7 @@ object QueryableMacros{ c.universe.reify{ Queryable.factory[S]( foo.splice )} } def map[T:c.WeakTypeTag, S:c.WeakTypeTag] - (c: scala.reflect.macros.Context) + (c: scala.reflect.macros.BlackboxContext) (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) } class Queryable[T]{ diff --git a/test/files/run/macro-reify-ref-to-packageless/Impls_1.scala b/test/files/run/macro-reify-ref-to-packageless/Impls_1.scala index f19fd239f9..bc0015774e 100644 --- a/test/files/run/macro-reify-ref-to-packageless/Impls_1.scala +++ b/test/files/run/macro-reify-ref-to-packageless/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { val `Answer to the Ultimate Question of Life, the Universe, and Everything` = 42 diff --git a/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala b/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala index f454fc430a..d89a5e380d 100644 --- a/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala +++ b/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx)(x: c.Expr[Int]) = { diff --git a/test/files/run/macro-reify-splice-splice/Macros_1.scala b/test/files/run/macro-reify-splice-splice/Macros_1.scala index efdd5dbaa2..691f22ad07 100644 --- a/test/files/run/macro-reify-splice-splice/Macros_1.scala +++ b/test/files/run/macro-reify-splice-splice/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Macros { def foo = macro Impls.foo diff --git a/test/files/run/macro-reify-staticXXX/Macros_1.scala b/test/files/run/macro-reify-staticXXX/Macros_1.scala index f12c8f7dcc..077271d582 100644 --- a/test/files/run/macro-reify-staticXXX/Macros_1.scala +++ b/test/files/run/macro-reify-staticXXX/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object B { override def toString = "object" } class C { override def toString = "class" } @@ -14,7 +14,7 @@ object foo { } object packageless { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ reify { println(B) @@ -31,7 +31,7 @@ object packageless { package packageful { object Test { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ reify { println(B) diff --git a/test/files/run/macro-reify-tagful-a/Macros_1.scala b/test/files/run/macro-reify-tagful-a/Macros_1.scala index f2512dcfaf..56d43c1c53 100644 --- a/test/files/run/macro-reify-tagful-a/Macros_1.scala +++ b/test/files/run/macro-reify-tagful-a/Macros_1.scala @@ -1,5 +1,5 @@ import scala.reflect.runtime.universe._ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Macros { def foo[T](s: T) = macro Impls.foo[T] diff --git a/test/files/run/macro-reify-tagless-a/Impls_Macros_1.scala b/test/files/run/macro-reify-tagless-a/Impls_Macros_1.scala index 96cfb75852..27acaa1626 100644 --- a/test/files/run/macro-reify-tagless-a/Impls_Macros_1.scala +++ b/test/files/run/macro-reify-tagless-a/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Macros { def foo[T](s: T) = macro Impls.foo[T] diff --git a/test/files/run/macro-reify-type/Macros_1.scala b/test/files/run/macro-reify-type/Macros_1.scala index c4d1d9f8ad..04634b649a 100644 --- a/test/files/run/macro-reify-type/Macros_1.scala +++ b/test/files/run/macro-reify-type/Macros_1.scala @@ -1,10 +1,10 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import scala.reflect.runtime.{universe => ru} object StaticReflect { def method[A](name: String): ru.Type = macro methodImpl[A] - def methodImpl[A: c.WeakTypeTag](c: Context)(name: c.Expr[String]): c.Expr[ru.Type] = { + def methodImpl[A: c.WeakTypeTag](c: BlackboxContext)(name: c.Expr[String]): c.Expr[ru.Type] = { import c.universe._ val nameName: TermName = name.tree match { diff --git a/test/files/run/macro-reify-unreify/Macros_1.scala b/test/files/run/macro-reify-unreify/Macros_1.scala index 25ed352cca..d1e71b3311 100644 --- a/test/files/run/macro-reify-unreify/Macros_1.scala +++ b/test/files/run/macro-reify-unreify/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Macros { def foo(s: String) = macro Impls.foo diff --git a/test/files/run/macro-repl-basic.check b/test/files/run/macro-repl-basic.check index 46ea1f6405..cc974897f2 100644 --- a/test/files/run/macro-repl-basic.check +++ b/test/files/run/macro-repl-basic.check @@ -4,8 +4,8 @@ Type :help for more information. scala> import language.experimental.macros import language.experimental.macros -scala> import scala.reflect.macros.{Context => Ctx} -import scala.reflect.macros.{Context=>Ctx} +scala> import scala.reflect.macros.{BlackboxContext => Ctx} +import scala.reflect.macros.{BlackboxContext=>Ctx} scala> diff --git a/test/files/run/macro-repl-basic.scala b/test/files/run/macro-repl-basic.scala index 3c22c13dc7..dea36c481c 100644 --- a/test/files/run/macro-repl-basic.scala +++ b/test/files/run/macro-repl-basic.scala @@ -3,7 +3,7 @@ import scala.tools.partest.ReplTest object Test extends ReplTest { def code = """ |import language.experimental.macros - |import scala.reflect.macros.{Context => Ctx} + |import scala.reflect.macros.{BlackboxContext => Ctx} | |object Impls { | def foo(c: Ctx)(x: c.Expr[Int]) = { diff --git a/test/files/run/macro-repl-dontexpand.check b/test/files/run/macro-repl-dontexpand.check index 9c35aad6b1..3ba877b59d 100644 --- a/test/files/run/macro-repl-dontexpand.check +++ b/test/files/run/macro-repl-dontexpand.check @@ -1,10 +1,16 @@ Type in expressions to have them evaluated. Type :help for more information. -scala> def bar(c: scala.reflect.macros.Context) = ??? -bar: (c: scala.reflect.macros.Context)Nothing +scala> def bar1(c: scala.reflect.macros.BlackboxContext) = ??? +bar1: (c: scala.reflect.macros.BlackboxContext)Nothing -scala> def foo = macro bar -defined term macro foo: Any +scala> def foo1 = macro bar1 +defined term macro foo1: Any + +scala> def bar2(c: scala.reflect.macros.WhiteboxContext) = ??? +bar2: (c: scala.reflect.macros.WhiteboxContext)Nothing + +scala> def foo2 = macro bar2 +defined term macro foo2: Any scala> diff --git a/test/files/run/macro-repl-dontexpand.scala b/test/files/run/macro-repl-dontexpand.scala index f3422d88de..733288e513 100644 --- a/test/files/run/macro-repl-dontexpand.scala +++ b/test/files/run/macro-repl-dontexpand.scala @@ -3,7 +3,9 @@ import scala.tools.partest.ReplTest object Test extends ReplTest { override def extraSettings = "-language:experimental.macros" def code = """ - |def bar(c: scala.reflect.macros.Context) = ??? - |def foo = macro bar + |def bar1(c: scala.reflect.macros.BlackboxContext) = ??? + |def foo1 = macro bar1 + |def bar2(c: scala.reflect.macros.WhiteboxContext) = ??? + |def foo2 = macro bar2 |""".stripMargin } diff --git a/test/files/run/macro-settings/Impls_Macros_1.scala b/test/files/run/macro-settings/Impls_Macros_1.scala index 9257784cf2..c9cecfa99f 100644 --- a/test/files/run/macro-settings/Impls_Macros_1.scala +++ b/test/files/run/macro-settings/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Impls { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ reify { println(c.Expr[String](Literal(Constant(c.settings.toString))).splice) diff --git a/test/files/run/macro-sip19-revised/Impls_Macros_1.scala b/test/files/run/macro-sip19-revised/Impls_Macros_1.scala index 1b914ac797..870930c7e5 100644 --- a/test/files/run/macro-sip19-revised/Impls_Macros_1.scala +++ b/test/files/run/macro-sip19-revised/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ val inscope = c.inferImplicitValue(c.mirror.staticClass("SourceLocation").toType) diff --git a/test/files/run/macro-sip19/Impls_Macros_1.scala b/test/files/run/macro-sip19/Impls_Macros_1.scala index 95e19c4fd1..72a3c2568d 100644 --- a/test/files/run/macro-sip19/Impls_Macros_1.scala +++ b/test/files/run/macro-sip19/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ val Apply(fun, args) = c.enclosingImplicits(0).tree val fileName = fun.pos.source.file.file.getName diff --git a/test/files/run/macro-system-properties.check b/test/files/run/macro-system-properties.check index c61fe7f2cf..ea4c5a664a 100644 --- a/test/files/run/macro-system-properties.check +++ b/test/files/run/macro-system-properties.check @@ -1,14 +1,14 @@ Type in expressions to have them evaluated. Type :help for more information. -scala> import language.experimental._, reflect.macros.Context +scala> import language.experimental._, reflect.macros.BlackboxContext import language.experimental._ -import reflect.macros.Context +import reflect.macros.BlackboxContext scala> object GrabContext { def lastContext = Option(System.getProperties.get("lastContext").asInstanceOf[reflect.macros.runtime.Context]) // System.properties lets you stash true globals (unlike statics which are classloader scoped) - def impl(c: Context)() = { import c.universe._; System.getProperties.put("lastContext", c); c.Expr[Unit](q"()") } + def impl(c: BlackboxContext)() = { import c.universe._; System.getProperties.put("lastContext", c); c.Expr[Unit](q"()") } def grab() = macro impl } defined object GrabContext diff --git a/test/files/run/macro-system-properties.scala b/test/files/run/macro-system-properties.scala index 9dcd044dbd..73a3ef5910 100644 --- a/test/files/run/macro-system-properties.scala +++ b/test/files/run/macro-system-properties.scala @@ -3,11 +3,11 @@ import scala.tools.partest.ReplTest object Test extends ReplTest { def code = """ - import language.experimental._, reflect.macros.Context + import language.experimental._, reflect.macros.BlackboxContext object GrabContext { def lastContext = Option(System.getProperties.get("lastContext").asInstanceOf[reflect.macros.runtime.Context]) // System.properties lets you stash true globals (unlike statics which are classloader scoped) - def impl(c: Context)() = { import c.universe._; System.getProperties.put("lastContext", c); c.Expr[Unit](q"()") } + def impl(c: BlackboxContext)() = { import c.universe._; System.getProperties.put("lastContext", c); c.Expr[Unit](q"()") } def grab() = macro impl } object Test { class C(implicit a: Any) { GrabContext.grab } } diff --git a/test/files/run/macro-term-declared-in-annotation/Impls_1.scala b/test/files/run/macro-term-declared-in-annotation/Impls_1.scala index 1ea06de679..df3509731b 100644 --- a/test/files/run/macro-term-declared-in-annotation/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-annotation/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-anonymous/Impls_1.scala b/test/files/run/macro-term-declared-in-anonymous/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-anonymous/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-anonymous/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-block/Impls_1.scala b/test/files/run/macro-term-declared-in-block/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-block/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-block/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-class-class/Impls_1.scala b/test/files/run/macro-term-declared-in-class-class/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-class-class/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-class-class/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-class-object/Impls_1.scala b/test/files/run/macro-term-declared-in-class-object/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-class-object/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-class-object/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-class/Impls_1.scala b/test/files/run/macro-term-declared-in-class/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-class/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-class/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-default-param/Impls_1.scala b/test/files/run/macro-term-declared-in-default-param/Impls_1.scala index 4380f40b04..4fae9b200f 100644 --- a/test/files/run/macro-term-declared-in-default-param/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-default-param/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-implicit-class/Impls_Macros_1.scala b/test/files/run/macro-term-declared-in-implicit-class/Impls_Macros_1.scala index 4c009cc367..053af625a2 100644 --- a/test/files/run/macro-term-declared-in-implicit-class/Impls_Macros_1.scala +++ b/test/files/run/macro-term-declared-in-implicit-class/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def toOptionOfInt(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-method/Impls_1.scala b/test/files/run/macro-term-declared-in-method/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-method/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-method/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-object-class/Impls_1.scala b/test/files/run/macro-term-declared-in-object-class/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-object-class/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-object-class/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-object-object/Impls_1.scala b/test/files/run/macro-term-declared-in-object-object/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-object-object/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-object-object/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-object/Impls_1.scala b/test/files/run/macro-term-declared-in-object/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-object/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-object/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-package-object/Impls_1.scala b/test/files/run/macro-term-declared-in-package-object/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-package-object/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-package-object/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-refinement/Impls_1.scala b/test/files/run/macro-term-declared-in-refinement/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-refinement/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-refinement/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-term-declared-in-trait/Impls_1.scala b/test/files/run/macro-term-declared-in-trait/Impls_1.scala index 348f3420f2..d69422872b 100644 --- a/test/files/run/macro-term-declared-in-trait/Impls_1.scala +++ b/test/files/run/macro-term-declared-in-trait/Impls_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} object Impls { def foo(c: Ctx) = { diff --git a/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala b/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala index cd37c269b5..9f7d6f641c 100644 --- a/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl_with_implicits_enabled(c: Context) = { + def impl_with_implicits_enabled(c: BlackboxContext) = { import c.universe._ val tree1 = Apply(Select(Literal(Constant(1)), TermName("$minus$greater")), List(Literal(Constant(2)))) @@ -11,7 +11,7 @@ object Macros { def foo_with_implicits_enabled = macro impl_with_implicits_enabled - def impl_with_implicits_disabled(c: Context) = { + def impl_with_implicits_disabled(c: BlackboxContext) = { import c.universe._ try { diff --git a/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala b/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala index 2532cfd2b9..41e58e0e4d 100644 --- a/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl_with_macros_enabled(c: Context) = { + def impl_with_macros_enabled(c: BlackboxContext) = { import c.universe._ val ru = Select(Select(Select(Select(Ident(TermName("scala")), TermName("reflect")), TermName("runtime")), TermName("package")), TermName("universe")) @@ -12,7 +12,7 @@ object Macros { def foo_with_macros_enabled = macro impl_with_macros_enabled - def impl_with_macros_disabled(c: Context) = { + def impl_with_macros_disabled(c: BlackboxContext) = { import c.universe._ val rupkg = c.mirror.staticModule("scala.reflect.runtime.package") diff --git a/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala b/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala index 7b22793df9..3d12020109 100644 --- a/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl_with_macros_enabled(c: Context) = { + def impl_with_macros_enabled(c: BlackboxContext) = { import c.universe._ val ru = Select(Select(Select(Select(Ident(TermName("scala")), TermName("reflect")), TermName("runtime")), TermName("package")), TermName("universe")) @@ -12,7 +12,7 @@ object Macros { def foo_with_macros_enabled = macro impl_with_macros_enabled - def impl_with_macros_disabled(c: Context) = { + def impl_with_macros_disabled(c: BlackboxContext) = { import c.universe._ val rupkg = c.mirror.staticModule("scala.reflect.runtime.package") diff --git a/test/files/run/macro-undetparams-consfromsls/Impls_Macros_1.scala b/test/files/run/macro-undetparams-consfromsls/Impls_Macros_1.scala index 6695a297ea..1af0579abc 100644 --- a/test/files/run/macro-undetparams-consfromsls/Impls_Macros_1.scala +++ b/test/files/run/macro-undetparams-consfromsls/Impls_Macros_1.scala @@ -1,8 +1,8 @@ import scala.reflect.runtime.universe._ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def cons_impl[A: c.WeakTypeTag](c: Context)(x: c.Expr[A], xs: c.Expr[List[A]]): c.Expr[List[A]] = { + def cons_impl[A: c.WeakTypeTag](c: BlackboxContext)(x: c.Expr[A], xs: c.Expr[List[A]]): c.Expr[List[A]] = { import c.universe._ reify { println("A = " + c.Expr[String](Literal(Constant(implicitly[c.WeakTypeTag[A]].toString))).splice) @@ -10,7 +10,7 @@ object Macros { } } - def nil_impl[B: c.WeakTypeTag](c: Context): c.Expr[List[B]] = { + def nil_impl[B: c.WeakTypeTag](c: BlackboxContext): c.Expr[List[B]] = { import c.universe._ reify { println("B = " + c.Expr[String](Literal(Constant(implicitly[c.WeakTypeTag[B]].toString))).splice) diff --git a/test/files/run/macro-undetparams-macroitself/Impls_Macros_1.scala b/test/files/run/macro-undetparams-macroitself/Impls_Macros_1.scala index 85877b3f13..f698320579 100644 --- a/test/files/run/macro-undetparams-macroitself/Impls_Macros_1.scala +++ b/test/files/run/macro-undetparams-macroitself/Impls_Macros_1.scala @@ -1,8 +1,8 @@ import scala.reflect.runtime.universe._ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl[T: c.WeakTypeTag](c: Context)(foo: c.Expr[T]): c.Expr[Unit] = { + def impl[T: c.WeakTypeTag](c: BlackboxContext)(foo: c.Expr[T]): c.Expr[Unit] = { import c.universe._ reify { println(c.Expr[String](Literal(Constant(implicitly[c.WeakTypeTag[T]].toString))).splice) } } diff --git a/test/files/run/macro-vampire-false-warning/Macros_1.scala b/test/files/run/macro-vampire-false-warning/Macros_1.scala index 2d384fbb85..5907461c84 100644 --- a/test/files/run/macro-vampire-false-warning/Macros_1.scala +++ b/test/files/run/macro-vampire-false-warning/Macros_1.scala @@ -1,20 +1,20 @@ // As per http://meta.plasm.us/posts/2013/08/31/feeding-our-vampires/ import scala.annotation.StaticAnnotation -import scala.reflect.macros.Context +import scala.reflect.macros.WhiteboxContext import scala.language.experimental.macros class body(tree: Any) extends StaticAnnotation object Macros { - def selFieldImpl(c: Context) = { + def selFieldImpl(c: WhiteboxContext) = { import c.universe._ val field = c.macroApplication.symbol val bodyAnn = field.annotations.filter(_.tpe <:< typeOf[body]).head c.Expr[Any](bodyAnn.scalaArgs.head) } - def mkObjectImpl(c: Context)(xs: c.Expr[Any]*) = { + def mkObjectImpl(c: WhiteboxContext)(xs: c.Expr[Any]*) = { import c.universe._ import Flag._ // val kvps = xs.toList map { case q"${_}(${Literal(Constant(name: String))}).->[${_}]($value)" => name -> value } diff --git a/test/files/run/repl-term-macros.check b/test/files/run/repl-term-macros.check index 63bafe401b..64c46392a3 100644 --- a/test/files/run/repl-term-macros.check +++ b/test/files/run/repl-term-macros.check @@ -1,16 +1,16 @@ Type in expressions to have them evaluated. Type :help for more information. -scala> import scala.reflect.macros.Context -import scala.reflect.macros.Context +scala> import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.BlackboxContext scala> import language.experimental.macros import language.experimental.macros scala> -scala> def impl1(c: Context) = { import c.universe._; c.Expr[Unit](q"()") } -impl1: (c: scala.reflect.macros.Context)c.Expr[Unit] +scala> def impl1(c: BlackboxContext) = { import c.universe._; c.Expr[Unit](q"()") } +impl1: (c: scala.reflect.macros.BlackboxContext)c.Expr[Unit] scala> def foo1 = macro impl1 defined term macro foo1: Unit @@ -19,8 +19,8 @@ scala> foo1 scala> -scala> def impl2(c: Context)() = { import c.universe._; c.Expr[Unit](q"()") } -impl2: (c: scala.reflect.macros.Context)()c.Expr[Unit] +scala> def impl2(c: BlackboxContext)() = { import c.universe._; c.Expr[Unit](q"()") } +impl2: (c: scala.reflect.macros.BlackboxContext)()c.Expr[Unit] scala> def foo2() = macro impl2 defined term macro foo2: ()Unit @@ -29,8 +29,8 @@ scala> foo2() scala> -scala> def impl3(c: Context)(x: c.Expr[Int])(y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } -impl3: (c: scala.reflect.macros.Context)(x: c.Expr[Int])(y: c.Expr[Int])c.Expr[Unit] +scala> def impl3(c: BlackboxContext)(x: c.Expr[Int])(y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } +impl3: (c: scala.reflect.macros.BlackboxContext)(x: c.Expr[Int])(y: c.Expr[Int])c.Expr[Unit] scala> def foo3(x: Int)(y: Int) = macro impl3 defined term macro foo3: (x: Int)(y: Int)Unit diff --git a/test/files/run/repl-term-macros.scala b/test/files/run/repl-term-macros.scala index 125e397b22..a779638c00 100644 --- a/test/files/run/repl-term-macros.scala +++ b/test/files/run/repl-term-macros.scala @@ -2,18 +2,18 @@ import scala.tools.partest.ReplTest object Test extends ReplTest { def code = """ - import scala.reflect.macros.Context + import scala.reflect.macros.BlackboxContext import language.experimental.macros -def impl1(c: Context) = { import c.universe._; c.Expr[Unit](q"()") } +def impl1(c: BlackboxContext) = { import c.universe._; c.Expr[Unit](q"()") } def foo1 = macro impl1 foo1 -def impl2(c: Context)() = { import c.universe._; c.Expr[Unit](q"()") } +def impl2(c: BlackboxContext)() = { import c.universe._; c.Expr[Unit](q"()") } def foo2() = macro impl2 foo2() -def impl3(c: Context)(x: c.Expr[Int])(y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } +def impl3(c: BlackboxContext)(x: c.Expr[Int])(y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"()") } def foo3(x: Int)(y: Int) = macro impl3 foo3(2)(3) """ diff --git a/test/files/run/t5713/Impls_Macros_1.scala b/test/files/run/t5713/Impls_Macros_1.scala index 12c3da2ff0..bfe2fc4efd 100644 --- a/test/files/run/t5713/Impls_Macros_1.scala +++ b/test/files/run/t5713/Impls_Macros_1.scala @@ -1,7 +1,7 @@ package m import language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Level extends Enumeration { val Error = Value(5) @@ -13,7 +13,7 @@ object Logger { private object LoggerMacros { - type LoggerContext = Context { type PrefixType = Logger.type } + type LoggerContext = BlackboxContext { type PrefixType = Logger.type } def error(c: LoggerContext)(message: c.Expr[String]): c.Expr[Unit] = log(c)(c.universe.reify(Level.Error), message) diff --git a/test/files/run/t5753_1/Impls_Macros_1.scala b/test/files/run/t5753_1/Impls_Macros_1.scala index 1664301f5f..3ddff56c38 100644 --- a/test/files/run/t5753_1/Impls_Macros_1.scala +++ b/test/files/run/t5753_1/Impls_Macros_1.scala @@ -1,8 +1,8 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros trait Impls { - def impl(c: Context)(x: c.Expr[Any]) = x + def impl(c: BlackboxContext)(x: c.Expr[Any]) = x } object Macros extends Impls { diff --git a/test/files/run/t5753_2/Impls_Macros_1.scala b/test/files/run/t5753_2/Impls_Macros_1.scala index 41d584d0ac..c95c9a41b3 100644 --- a/test/files/run/t5753_2/Impls_Macros_1.scala +++ b/test/files/run/t5753_2/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.{Context => Ctx} +import scala.reflect.macros.{BlackboxContext => Ctx} trait Macro_T { def foo[T](c: Ctx)(s: c.Expr[T]) = s diff --git a/test/files/run/t5894.scala b/test/files/run/t5894.scala index 5deda34489..55767d8889 100644 --- a/test/files/run/t5894.scala +++ b/test/files/run/t5894.scala @@ -4,7 +4,7 @@ class Test object Test { def foo = macro fooImpl - def fooImpl(c: reflect.macros.Context) = { import c.universe._; c.Expr[Unit](q"()") } + def fooImpl(c: reflect.macros.BlackboxContext) = { import c.universe._; c.Expr[Unit](q"()") } def main(args: Array[String]) { try { diff --git a/test/files/run/t5903a/Macros_1.scala b/test/files/run/t5903a/Macros_1.scala index e82be0fc68..9fc3bfe261 100644 --- a/test/files/run/t5903a/Macros_1.scala +++ b/test/files/run/t5903a/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros trait Tree @@ -13,7 +13,7 @@ object NewQuasiquotes { } object QuasiquoteMacros { - def unapplyImpl(c: Context)(t: c.Tree) = { + def unapplyImpl(c: BlackboxContext)(t: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5903b/Macros_1.scala b/test/files/run/t5903b/Macros_1.scala index c0124850b8..ae491e2207 100644 --- a/test/files/run/t5903b/Macros_1.scala +++ b/test/files/run/t5903b/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl[T: c.WeakTypeTag](c: Context)(x: c.Tree) = { + def unapplyImpl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5903c/Macros_1.scala b/test/files/run/t5903c/Macros_1.scala index f8baa2275b..da7dd5281c 100644 --- a/test/files/run/t5903c/Macros_1.scala +++ b/test/files/run/t5903c/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl[T: c.WeakTypeTag](c: Context)(x: c.Tree) = { + def unapplyImpl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5903d/Macros_1.scala b/test/files/run/t5903d/Macros_1.scala index 88d714e17b..e3a9c3b39e 100644 --- a/test/files/run/t5903d/Macros_1.scala +++ b/test/files/run/t5903d/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl(c: Context)(x: c.Tree) = { + def unapplyImpl(c: BlackboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5923a/Macros_1.scala b/test/files/run/t5923a/Macros_1.scala index 741379cf34..f86e6b1add 100644 --- a/test/files/run/t5923a/Macros_1.scala +++ b/test/files/run/t5923a/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros case class C[T](t: String) @@ -7,7 +7,7 @@ object C { } object Macros { - def impl[T](c: Context)(ttag: c.WeakTypeTag[T]) = { + def impl[T](c: BlackboxContext)(ttag: c.WeakTypeTag[T]) = { import c.universe._ val ttag0 = ttag; { diff --git a/test/files/run/t5923c/Macros_1.scala b/test/files/run/t5923c/Macros_1.scala index 0b7a3399e2..c980f243d4 100644 --- a/test/files/run/t5923c/Macros_1.scala +++ b/test/files/run/t5923c/Macros_1.scala @@ -1,5 +1,5 @@ import language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext trait Iso[T, U] { def to(t : T) : U @@ -8,7 +8,7 @@ trait Iso[T, U] { object Iso { implicit def materializeIso[T, U]: Iso[T, U] = macro impl[T, U] - def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: Context): c.Expr[Iso[T, U]] = { + def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: BlackboxContext): c.Expr[Iso[T, U]] = { import c.universe._ import definitions._ import Flag._ diff --git a/test/files/run/t5923d/Macros_1.scala b/test/files/run/t5923d/Macros_1.scala index f32d1af704..b6e7134b95 100644 --- a/test/files/run/t5923d/Macros_1.scala +++ b/test/files/run/t5923d/Macros_1.scala @@ -1,9 +1,9 @@ import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext trait MappedRow trait RowMapper[T <: MappedRow] object RowMapper { implicit def mapper[T <: MappedRow]: RowMapper[T] = macro impl[T] - def impl[T <: MappedRow : c.WeakTypeTag](c: Context) = c.universe.reify(new RowMapper[T]{}) + def impl[T <: MappedRow : c.WeakTypeTag](c: BlackboxContext) = c.universe.reify(new RowMapper[T]{}) } \ No newline at end of file diff --git a/test/files/run/t5940.scala b/test/files/run/t5940.scala index 9c8f702c68..d98f267123 100644 --- a/test/files/run/t5940.scala +++ b/test/files/run/t5940.scala @@ -4,15 +4,15 @@ object Test extends DirectTest { def code = ??? def macros_1 = """ - import scala.reflect.macros.Context + import scala.reflect.macros.BlackboxContext object Impls { - def impl(c: Context) = { import c.universe._; c.Expr[Unit](q"()") } + def impl(c: BlackboxContext) = { import c.universe._; c.Expr[Unit](q"()") } } object Macros { //import Impls._ - def impl(c: Context) = { import c.universe._; c.Expr[Unit](q"()") } + def impl(c: BlackboxContext) = { import c.universe._; c.Expr[Unit](q"()") } def foo = macro impl } """ diff --git a/test/files/run/t6187.check b/test/files/run/t6187.check index 621306b2ef..c833b45443 100644 --- a/test/files/run/t6187.check +++ b/test/files/run/t6187.check @@ -1,15 +1,15 @@ Type in expressions to have them evaluated. Type :help for more information. -scala> import language.experimental.macros, reflect.macros.Context +scala> import language.experimental.macros, reflect.macros.BlackboxContext import language.experimental.macros -import reflect.macros.Context +import reflect.macros.BlackboxContext -scala> def macroImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[List[T]] = { +scala> def macroImpl[T: c.WeakTypeTag](c: BlackboxContext)(t: c.Expr[T]): c.Expr[List[T]] = { val r = c.universe.reify { List(t.splice) } c.Expr[List[T]]( c.resetLocalAttrs(r.tree) ) } -macroImpl: [T](c: scala.reflect.macros.Context)(t: c.Expr[T])(implicit evidence$1: c.WeakTypeTag[T])c.Expr[List[T]] +macroImpl: [T](c: scala.reflect.macros.BlackboxContext)(t: c.Expr[T])(implicit evidence$1: c.WeakTypeTag[T])c.Expr[List[T]] scala> def demo[T](t: T): List[T] = macro macroImpl[T] defined term macro demo: [T](t: T)List[T] diff --git a/test/files/run/t6187.scala b/test/files/run/t6187.scala index ae642917e7..fc6fa6e9a7 100644 --- a/test/files/run/t6187.scala +++ b/test/files/run/t6187.scala @@ -2,8 +2,8 @@ import scala.tools.partest.ReplTest object Test extends ReplTest { override def code = """ -import language.experimental.macros, reflect.macros.Context -def macroImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[List[T]] = { +import language.experimental.macros, reflect.macros.BlackboxContext +def macroImpl[T: c.WeakTypeTag](c: BlackboxContext)(t: c.Expr[T]): c.Expr[List[T]] = { val r = c.universe.reify { List(t.splice) } c.Expr[List[T]]( c.resetLocalAttrs(r.tree) ) } diff --git a/test/files/run/t6221/Macros_1.scala b/test/files/run/t6221/Macros_1.scala index c9500626d8..60ed0aa3e3 100644 --- a/test/files/run/t6221/Macros_1.scala +++ b/test/files/run/t6221/Macros_1.scala @@ -1,6 +1,6 @@ import language.experimental.macros import language.implicitConversions -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import scala.reflect.runtime.universe.Tree class ReflectiveClosure[A, B](val tree: Tree, fn: A => B) extends (A => B) { @@ -12,7 +12,7 @@ object ReflectiveClosure { } object Macros { - def reflectiveClosureImpl[A, B](c: Context)(f: c.Expr[A => B]): c.Expr[ReflectiveClosure[A, B]] = { + def reflectiveClosureImpl[A, B](c: BlackboxContext)(f: c.Expr[A => B]): c.Expr[ReflectiveClosure[A, B]] = { import c.universe._ val u = treeBuild.mkRuntimeUniverseRef val m = EmptyTree diff --git a/test/files/run/t6381.check b/test/files/run/t6381.check index c9d4713aa8..dfc9d44850 100644 --- a/test/files/run/t6381.check +++ b/test/files/run/t6381.check @@ -4,11 +4,11 @@ Type :help for more information. scala> import language.experimental.macros import language.experimental.macros -scala> def pos_impl(c: reflect.macros.Context): c.Expr[String] = { +scala> def pos_impl(c: reflect.macros.BlackboxContext): c.Expr[String] = { import c.universe._ c.Expr[String](Literal(Constant(c.enclosingPosition.getClass.toString))) } -pos_impl: (c: scala.reflect.macros.Context)c.Expr[String] +pos_impl: (c: scala.reflect.macros.BlackboxContext)c.Expr[String] scala> def pos = macro pos_impl defined term macro pos: String diff --git a/test/files/run/t6381.scala b/test/files/run/t6381.scala index 4c2a40fe87..0e2264d8fa 100644 --- a/test/files/run/t6381.scala +++ b/test/files/run/t6381.scala @@ -3,7 +3,7 @@ import scala.tools.partest.ReplTest object Test extends ReplTest { def code = """ |import language.experimental.macros - |def pos_impl(c: reflect.macros.Context): c.Expr[String] = { + |def pos_impl(c: reflect.macros.BlackboxContext): c.Expr[String] = { | import c.universe._ | c.Expr[String](Literal(Constant(c.enclosingPosition.getClass.toString))) |} diff --git a/test/files/run/t6394a/Macros_1.scala b/test/files/run/t6394a/Macros_1.scala index 5aa07e7f41..b934b5ebb1 100644 --- a/test/files/run/t6394a/Macros_1.scala +++ b/test/files/run/t6394a/Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c:Context): c.Expr[Any] = { + def impl(c:BlackboxContext): c.Expr[Any] = { import c.universe._ val selfTree = This(c.enclosingImpl.symbol.asModule.moduleClass) diff --git a/test/files/run/t6394b/Macros_1.scala b/test/files/run/t6394b/Macros_1.scala index 5d93e1cda8..01fbc4f09e 100644 --- a/test/files/run/t6394b/Macros_1.scala +++ b/test/files/run/t6394b/Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c:Context): c.Expr[Any] = { + def impl(c:BlackboxContext): c.Expr[Any] = { import c.universe._ val selfTree = This(tpnme.EMPTY) diff --git a/test/files/run/t6662/Macro_1.scala b/test/files/run/t6662/Macro_1.scala index f373eaaf94..cecf242f66 100644 --- a/test/files/run/t6662/Macro_1.scala +++ b/test/files/run/t6662/Macro_1.scala @@ -1,8 +1,8 @@ import language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Demo { def id[T](a: T): T = macro idImpl[T] - def idImpl[T: c.WeakTypeTag](c: Context)(a: c.Expr[T]): c.Expr[T] = a + def idImpl[T: c.WeakTypeTag](c: BlackboxContext)(a: c.Expr[T]): c.Expr[T] = a } diff --git a/test/files/run/t7008-scala-defined/Impls_Macros_2.scala b/test/files/run/t7008-scala-defined/Impls_Macros_2.scala index 477829f200..0ce5daf0d0 100644 --- a/test/files/run/t7008-scala-defined/Impls_Macros_2.scala +++ b/test/files/run/t7008-scala-defined/Impls_Macros_2.scala @@ -1,8 +1,8 @@ import language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ val decls = c.typeOf[ScalaClassWithCheckedExceptions_1[_]].declarations.toList val s = decls.sortBy(_.name.toString).map(decl => (s"${decl.name}: ${decl.annotations}")).mkString(scala.compat.Platform.EOL) diff --git a/test/files/run/t7008/Impls_Macros_2.scala b/test/files/run/t7008/Impls_Macros_2.scala index 63c3f9d696..6da9dca913 100644 --- a/test/files/run/t7008/Impls_Macros_2.scala +++ b/test/files/run/t7008/Impls_Macros_2.scala @@ -1,8 +1,8 @@ import language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ val decls = c.typeOf[JavaClassWithCheckedExceptions_1[_]].declarations.toList val s = decls.sortBy(_.name.toString).map(decl => (s"${decl.name}: ${decl.annotations}")).mkString(scala.compat.Platform.EOL) diff --git a/test/files/run/t7047/Impls_Macros_1.scala b/test/files/run/t7047/Impls_Macros_1.scala index a5d55c3a42..0d64729791 100644 --- a/test/files/run/t7047/Impls_Macros_1.scala +++ b/test/files/run/t7047/Impls_Macros_1.scala @@ -1,10 +1,10 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros class Foo object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ try { c.inferImplicitValue(typeOf[Foo], silent = false) diff --git a/test/files/run/t7157/Impls_Macros_1.scala b/test/files/run/t7157/Impls_Macros_1.scala index ad3d96eb85..e48fbcaed3 100644 --- a/test/files/run/t7157/Impls_Macros_1.scala +++ b/test/files/run/t7157/Impls_Macros_1.scala @@ -1,9 +1,9 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Macros { object AImpl { - def a(ctx: Context)(args: ctx.Expr[Any]*): ctx.Expr[Unit] = { + def a(ctx: BlackboxContext)(args: ctx.Expr[Any]*): ctx.Expr[Unit] = { import ctx.universe._ ctx.Expr[Unit](Apply(Ident(TermName("println")), List(Literal(Constant(1))))) } diff --git a/test/files/run/t7240/Macros_1.scala b/test/files/run/t7240/Macros_1.scala index 6465e18760..84ad231043 100644 --- a/test/files/run/t7240/Macros_1.scala +++ b/test/files/run/t7240/Macros_1.scala @@ -1,7 +1,7 @@ package bakery import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext trait FailureCake { implicit def liftAnyFails[T: Manifest]: Any = ??? @@ -13,7 +13,7 @@ trait FailureCake { object Bakery { def failure: Any = macro failureImpl - def failureImpl(c: Context): c.Expr[Any] = { + def failureImpl(c: BlackboxContext): c.Expr[Any] = { import c.universe._ def dslTrait(dslName: String) = { diff --git a/test/files/run/t7375b/Macros_1.scala b/test/files/run/t7375b/Macros_1.scala index 7a307805db..bcd8e52172 100644 --- a/test/files/run/t7375b/Macros_1.scala +++ b/test/files/run/t7375b/Macros_1.scala @@ -1,5 +1,5 @@ import language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext class C1(val n: Int) extends AnyVal class C2(val n: Int) extends AnyRef @@ -9,7 +9,7 @@ object Macros { type F2 = C2 def foo = macro impl - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ def test[T: c.TypeTag] = reify(println(c.Expr[String](Literal(Constant(c.reifyRuntimeClass(c.typeOf[T]).toString))).splice)).tree def tests = Block(List(test[C1], test[C2], test[F1], test[F2]), Literal(Constant(()))) diff --git a/test/files/run/t7617a/Macros_1.scala b/test/files/run/t7617a/Macros_1.scala index f9772c83c0..d19f112bf4 100644 --- a/test/files/run/t7617a/Macros_1.scala +++ b/test/files/run/t7617a/Macros_1.scala @@ -1,12 +1,12 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros object Macros { - def getValueImpl[T](c: Context): c.Expr[T] = { + def getValueImpl[T](c: BlackboxContext): c.Expr[T] = { import c.universe._ c.Expr[T](Apply(Select(c.prefix.tree, newTermName("getVal")), Nil)) } - def setValueImpl[T](c: Context)(value: c.Expr[T]): c.Expr[Unit] = { + def setValueImpl[T](c: BlackboxContext)(value: c.Expr[T]): c.Expr[Unit] = { import c.universe._ c.Expr[Unit](Apply(Select(c.prefix.tree, newTermName("setVal")), List(value.tree))) } diff --git a/test/files/run/t7617b/Macros_1.scala b/test/files/run/t7617b/Macros_1.scala index bc919935c9..b1406f30bb 100644 --- a/test/files/run/t7617b/Macros_1.scala +++ b/test/files/run/t7617b/Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext object Macros { - def impl(c: Context)(name: c.Expr[String])(value: c.Expr[Any]) = { + def impl(c: BlackboxContext)(name: c.Expr[String])(value: c.Expr[Any]) = { import c.universe._ reify(println(s"${name.splice} = ${value.splice}")) } diff --git a/test/files/run/t7657/Macros_1.scala b/test/files/run/t7657/Macros_1.scala index b1e31aa2dd..9aac02031d 100644 --- a/test/files/run/t7657/Macros_1.scala +++ b/test/files/run/t7657/Macros_1.scala @@ -1,8 +1,8 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros trait T { def t(): Unit } abstract class A extends T { override def t(): Unit = () } -object Macro { def t(c: Context)(): c.Expr[Unit] = c.universe.reify(()) } +object Macro { def t(c: BlackboxContext)(): c.Expr[Unit] = c.universe.reify(()) } class C extends A { override def t(): Unit = macro Macro.t } diff --git a/test/files/run/toolbox_current_run_compiles.scala b/test/files/run/toolbox_current_run_compiles.scala index b48c998e64..bc6a9d343e 100644 --- a/test/files/run/toolbox_current_run_compiles.scala +++ b/test/files/run/toolbox_current_run_compiles.scala @@ -1,9 +1,9 @@ package pkg { - import scala.reflect.macros.Context + import scala.reflect.macros.BlackboxContext import scala.language.experimental.macros object Macros { - def impl[T: c.WeakTypeTag](c: Context) = { + def impl[T: c.WeakTypeTag](c: BlackboxContext) = { import c.universe._ val sym = c.weakTypeOf[T].typeSymbol val g = c.universe.asInstanceOf[scala.tools.nsc.Global] diff --git a/test/files/run/typed-annotated/Macros_1.scala b/test/files/run/typed-annotated/Macros_1.scala index dd18c63d90..42478cb988 100644 --- a/test/files/run/typed-annotated/Macros_1.scala +++ b/test/files/run/typed-annotated/Macros_1.scala @@ -1,10 +1,10 @@ -import scala.reflect.macros.Context +import scala.reflect.macros.BlackboxContext import language.experimental.macros class ann extends scala.annotation.StaticAnnotation object Macros { - def impl(c: Context) = { + def impl(c: BlackboxContext) = { import c.universe._ // val tpt = Annotated(Apply(Select(New(Ident(newTypeName("ann"))), nme.CONSTRUCTOR), List()), Ident(newTypeName("Int"))) val tpt = Annotated(Apply(Select(New(Ident(newTypeName("ann"))), nme.CONSTRUCTOR), List()), TypeTree(weakTypeOf[Int])) -- cgit v1.2.3 From a2b523a39b4e56eb9ab5d9a5639f5b59d425e354 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 2 Oct 2013 17:21:27 +0200 Subject: blackbox restriction #1: can't refine the official return type When an application of a blackbox macro expands into a tree `x`, the expansion is wrapped into a type ascription `(x: T)`, where `T` is the declared return type of the blackbox macro with type arguments and path dependencies applied in consistency with the particular macro application being expanded. This invalidates blackbox macros as an implementation vehicle of type providers. --- .../scala/tools/nsc/typechecker/Macros.scala | 26 +++++++++++++--------- test/files/neg/macro-blackbox-structural.check | 4 ++++ .../macro-blackbox-structural/Impls_Macros_1.scala | 15 +++++++++++++ .../neg/macro-blackbox-structural/Test_2.scala | 5 +++++ test/files/neg/t5903a/Macros_1.scala | 4 ++-- test/files/neg/t5903e/Macros_1.scala | 4 ++-- .../run/macro-bodyexpandstoimpl/Impls_1.scala | 4 ++-- .../macro-expand-unapply-a/Impls_Macros_1.scala | 4 ++-- test/files/run/macro-invalidusage-badret.check | 2 +- test/files/run/macro-system-properties.check | 6 +++++ test/files/run/macro-whitebox-structural.check | 1 + .../macro-whitebox-structural/Impls_Macros_1.scala | 16 +++++++++++++ .../run/macro-whitebox-structural/Test_2.scala | 5 +++++ test/files/run/t5903a/Macros_1.scala | 4 ++-- test/files/run/t5903b/Macros_1.scala | 4 ++-- test/files/run/t5903c/Macros_1.scala | 4 ++-- test/files/run/t5903d/Macros_1.scala | 4 ++-- test/files/run/t5923a/Macros_1.scala | 4 ++-- test/files/run/t5923c/Macros_1.scala | 4 ++-- 19 files changed, 89 insertions(+), 31 deletions(-) create mode 100644 test/files/neg/macro-blackbox-structural.check create mode 100644 test/files/neg/macro-blackbox-structural/Impls_Macros_1.scala create mode 100644 test/files/neg/macro-blackbox-structural/Test_2.scala create mode 100644 test/files/run/macro-whitebox-structural.check create mode 100644 test/files/run/macro-whitebox-structural/Impls_Macros_1.scala create mode 100644 test/files/run/macro-whitebox-structural/Test_2.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index f1b9bd4833..57358f72f5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -604,21 +604,27 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers { */ def macroExpandApply(typer: Typer, expandee: Tree, mode: Mode, pt: Type): Tree = { object expander extends TermMacroExpander(APPLY_ROLE, typer, expandee, mode, pt) { - override def onSuccess(expanded: Tree) = { + override def onSuccess(expanded0: Tree) = { + def approximate(tp: Type) = { + // approximation is necessary for whitebox macros to guide type inference + // read more in the comments for onDelayed below + if (isBlackbox(expandee)) tp + else { + val undetparams = tp collect { case tp if tp.typeSymbol.isTypeParameter => tp.typeSymbol } + deriveTypeWithWildcards(undetparams)(tp) + } + } + val macroPt = approximate(if (isNullaryInvocation(expandee)) expandee.tpe.finalResultType else expandee.tpe) + val expanded = if (isBlackbox(expandee)) atPos(enclosingMacroPosition.focus)(Typed(expanded0, TypeTree(macroPt))) else expanded0 + // prematurely annotate the tree with a macro expansion attachment // so that adapt called indirectly by typer.typed knows that it needs to apply the existential fixup linkExpandeeAndExpanded(expandee, expanded) - // approximation is necessary for whitebox macros to guide type inference - // read more in the comments for onDelayed below - def approximate(tp: Type) = { - val undetparams = tp collect { case tp if tp.typeSymbol.isTypeParameter => tp.typeSymbol } - deriveTypeWithWildcards(undetparams)(tp) - } - val macroPtApprox = approximate(if (isNullaryInvocation(expandee)) expandee.tpe.finalResultType else expandee.tpe) + // `macroExpandApply` is called from `adapt`, where implicit conversions are disabled // therefore we need to re-enable the conversions back temporarily - if (macroDebugVerbose) println(s"typecheck #1 (against macroPtApprox = $macroPtApprox): $expanded") - val expanded1 = typer.context.withImplicitsEnabled(typer.typed(expanded, mode, macroPtApprox)) + if (macroDebugVerbose) println(s"typecheck #1 (against macroPt = $macroPt): $expanded") + val expanded1 = typer.context.withImplicitsEnabled(typer.typed(expanded, mode, macroPt)) if (expanded1.isErrorTyped) { if (macroDebugVerbose) println(s"typecheck #1 has failed: ${typer.context.reportBuffer.errors}") expanded1 diff --git a/test/files/neg/macro-blackbox-structural.check b/test/files/neg/macro-blackbox-structural.check new file mode 100644 index 0000000000..86a218559c --- /dev/null +++ b/test/files/neg/macro-blackbox-structural.check @@ -0,0 +1,4 @@ +Test_2.scala:4: error: value x is not a member of Any + println(Macros.foo.x) + ^ +one error found diff --git a/test/files/neg/macro-blackbox-structural/Impls_Macros_1.scala b/test/files/neg/macro-blackbox-structural/Impls_Macros_1.scala new file mode 100644 index 0000000000..08f1c21e89 --- /dev/null +++ b/test/files/neg/macro-blackbox-structural/Impls_Macros_1.scala @@ -0,0 +1,15 @@ +import scala.language.experimental.macros + +object Macros { + def impl(c: scala.reflect.macros.BlackboxContext) = { + import c.universe._ + q""" + trait Foo { + def x = 2 + } + new Foo {} + """ + } + + def foo = macro impl +} \ No newline at end of file diff --git a/test/files/neg/macro-blackbox-structural/Test_2.scala b/test/files/neg/macro-blackbox-structural/Test_2.scala new file mode 100644 index 0000000000..ea6a817e34 --- /dev/null +++ b/test/files/neg/macro-blackbox-structural/Test_2.scala @@ -0,0 +1,5 @@ +import Macros._ + +object Test extends App { + println(Macros.foo.x) +} \ No newline at end of file diff --git a/test/files/neg/t5903a/Macros_1.scala b/test/files/neg/t5903a/Macros_1.scala index 9fc3bfe261..7888b888e1 100644 --- a/test/files/neg/t5903a/Macros_1.scala +++ b/test/files/neg/t5903a/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros trait Tree @@ -13,7 +13,7 @@ object NewQuasiquotes { } object QuasiquoteMacros { - def unapplyImpl(c: BlackboxContext)(t: c.Tree) = { + def unapplyImpl(c: WhiteboxContext)(t: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/neg/t5903e/Macros_1.scala b/test/files/neg/t5903e/Macros_1.scala index 13e168d529..997e6fd073 100644 --- a/test/files/neg/t5903e/Macros_1.scala +++ b/test/files/neg/t5903e/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl(c: BlackboxContext)(x: c.Tree) = { + def unapplyImpl(c: WhiteboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala b/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala index 9af3b18ccb..0a9f9a0ced 100644 --- a/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala +++ b/test/files/run/macro-bodyexpandstoimpl/Impls_1.scala @@ -1,11 +1,11 @@ import scala.language.experimental.macros -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.{BlackboxContext, WhiteboxContext} object Impls { def foo(c: BlackboxContext)(x: c.Expr[Int]) = x def refToFoo(dummy: Int) = macro refToFoo_impl - def refToFoo_impl(c: BlackboxContext)(dummy: c.Expr[Int]) = { + def refToFoo_impl(c: WhiteboxContext)(dummy: c.Expr[Int]) = { import c.universe._ val body = Select(Ident(TermName("Impls")), TermName("foo")) val global = c.universe.asInstanceOf[scala.tools.nsc.Global] diff --git a/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala b/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala index b837ffc43b..7bfff374e2 100644 --- a/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala +++ b/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala @@ -1,11 +1,11 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext object Helper { def unapplySeq[T](x: List[T]): Option[Seq[T]] = List.unapplySeq[T](x) } object Macros { - def impl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Expr[List[T]]) = { + def impl[T: c.WeakTypeTag](c: WhiteboxContext)(x: c.Expr[List[T]]) = { c.universe.reify(Helper.unapplySeq(x.splice)) } diff --git a/test/files/run/macro-invalidusage-badret.check b/test/files/run/macro-invalidusage-badret.check index 9225b716d6..e79550043f 100644 --- a/test/files/run/macro-invalidusage-badret.check +++ b/test/files/run/macro-invalidusage-badret.check @@ -1,5 +1,5 @@ reflective compilation has failed: type mismatch; - found : Int(42) + found : Int required: String diff --git a/test/files/run/macro-system-properties.check b/test/files/run/macro-system-properties.check index ea4c5a664a..b102d319ec 100644 --- a/test/files/run/macro-system-properties.check +++ b/test/files/run/macro-system-properties.check @@ -14,9 +14,15 @@ scala> object GrabContext { defined object GrabContext scala> object Test { class C(implicit a: Any) { GrabContext.grab } } +:12: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + object Test { class C(implicit a: Any) { GrabContext.grab } } + ^ defined object Test scala> object Test { class C(implicit a: Any) { GrabContext.grab } } +:12: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + object Test { class C(implicit a: Any) { GrabContext.grab } } + ^ defined object Test scala> diff --git a/test/files/run/macro-whitebox-structural.check b/test/files/run/macro-whitebox-structural.check new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/test/files/run/macro-whitebox-structural.check @@ -0,0 +1 @@ +2 diff --git a/test/files/run/macro-whitebox-structural/Impls_Macros_1.scala b/test/files/run/macro-whitebox-structural/Impls_Macros_1.scala new file mode 100644 index 0000000000..1b975ca850 --- /dev/null +++ b/test/files/run/macro-whitebox-structural/Impls_Macros_1.scala @@ -0,0 +1,16 @@ +import scala.reflect.macros.WhiteboxContext +import scala.language.experimental.macros + +object Macros { + def impl(c: WhiteboxContext) = { + import c.universe._ + q""" + trait Foo { + def x = 2 + } + new Foo {} + """ + } + + def foo = macro impl +} \ No newline at end of file diff --git a/test/files/run/macro-whitebox-structural/Test_2.scala b/test/files/run/macro-whitebox-structural/Test_2.scala new file mode 100644 index 0000000000..ea6a817e34 --- /dev/null +++ b/test/files/run/macro-whitebox-structural/Test_2.scala @@ -0,0 +1,5 @@ +import Macros._ + +object Test extends App { + println(Macros.foo.x) +} \ No newline at end of file diff --git a/test/files/run/t5903a/Macros_1.scala b/test/files/run/t5903a/Macros_1.scala index 9fc3bfe261..7888b888e1 100644 --- a/test/files/run/t5903a/Macros_1.scala +++ b/test/files/run/t5903a/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros trait Tree @@ -13,7 +13,7 @@ object NewQuasiquotes { } object QuasiquoteMacros { - def unapplyImpl(c: BlackboxContext)(t: c.Tree) = { + def unapplyImpl(c: WhiteboxContext)(t: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5903b/Macros_1.scala b/test/files/run/t5903b/Macros_1.scala index ae491e2207..8c03e5579d 100644 --- a/test/files/run/t5903b/Macros_1.scala +++ b/test/files/run/t5903b/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Tree) = { + def unapplyImpl[T: c.WeakTypeTag](c: WhiteboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5903c/Macros_1.scala b/test/files/run/t5903c/Macros_1.scala index da7dd5281c..c9dfe9d60c 100644 --- a/test/files/run/t5903c/Macros_1.scala +++ b/test/files/run/t5903c/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl[T: c.WeakTypeTag](c: BlackboxContext)(x: c.Tree) = { + def unapplyImpl[T: c.WeakTypeTag](c: WhiteboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5903d/Macros_1.scala b/test/files/run/t5903d/Macros_1.scala index e3a9c3b39e..8a57e27602 100644 --- a/test/files/run/t5903d/Macros_1.scala +++ b/test/files/run/t5903d/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros object Interpolation { @@ -10,7 +10,7 @@ object Interpolation { } object Macros { - def unapplyImpl(c: BlackboxContext)(x: c.Tree) = { + def unapplyImpl(c: WhiteboxContext)(x: c.Tree) = { import c.universe._ q""" new { diff --git a/test/files/run/t5923a/Macros_1.scala b/test/files/run/t5923a/Macros_1.scala index f86e6b1add..445392ff95 100644 --- a/test/files/run/t5923a/Macros_1.scala +++ b/test/files/run/t5923a/Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros case class C[T](t: String) @@ -7,7 +7,7 @@ object C { } object Macros { - def impl[T](c: BlackboxContext)(ttag: c.WeakTypeTag[T]) = { + def impl[T](c: WhiteboxContext)(ttag: c.WeakTypeTag[T]) = { import c.universe._ val ttag0 = ttag; { diff --git a/test/files/run/t5923c/Macros_1.scala b/test/files/run/t5923c/Macros_1.scala index c980f243d4..c86e14966b 100644 --- a/test/files/run/t5923c/Macros_1.scala +++ b/test/files/run/t5923c/Macros_1.scala @@ -1,5 +1,5 @@ import language.experimental.macros -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext trait Iso[T, U] { def to(t : T) : U @@ -8,7 +8,7 @@ trait Iso[T, U] { object Iso { implicit def materializeIso[T, U]: Iso[T, U] = macro impl[T, U] - def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: BlackboxContext): c.Expr[Iso[T, U]] = { + def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: WhiteboxContext): c.Expr[Iso[T, U]] = { import c.universe._ import definitions._ import Flag._ -- cgit v1.2.3 From 6038bac3513a834e67ab4074c2c7b03aac11b1b3 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 2 Oct 2013 17:21:55 +0200 Subject: blackbox restriction #2: can't guide type inference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an application of a blackbox macro still has undetermined type parameters after Scala’s type inference algorithm has finished working, these type parameters are inferred forcedly, in exactly the same manner as type inference happens for normal methods. This makes it impossible for blackbox macros to influence type inference, prohibiting fundep materialization. --- .../scala/tools/nsc/typechecker/Macros.scala | 11 +++--- .../macro-blackbox-fundep-materialization.check | 12 +++++++ .../macro-blackbox-fundep-materialization.flags | 1 + .../Macros_1.scala | 39 ++++++++++++++++++++++ .../Test_2.scala | 12 +++++++ .../files/run/macro-blackbox-materialization.check | 3 ++ .../macro-blackbox-materialization/Macros_1.scala | 16 +++++++++ .../macro-blackbox-materialization/Test_2.scala | 5 +++ .../macro-whitebox-fundep-materialization.check | 1 + .../Macros_1.scala | 39 ++++++++++++++++++++++ .../Test_2.scala | 12 +++++++ test/files/run/t5923c.check | 1 - test/files/run/t5923c.scala | 4 +++ test/files/run/t5923c/Macros_1.scala | 39 ---------------------- test/files/run/t5923c/Test_2.scala | 12 ------- 15 files changed, 151 insertions(+), 56 deletions(-) create mode 100644 test/files/neg/macro-blackbox-fundep-materialization.check create mode 100644 test/files/neg/macro-blackbox-fundep-materialization.flags create mode 100644 test/files/neg/macro-blackbox-fundep-materialization/Macros_1.scala create mode 100644 test/files/neg/macro-blackbox-fundep-materialization/Test_2.scala create mode 100644 test/files/run/macro-blackbox-materialization.check create mode 100644 test/files/run/macro-blackbox-materialization/Macros_1.scala create mode 100644 test/files/run/macro-blackbox-materialization/Test_2.scala create mode 100644 test/files/run/macro-whitebox-fundep-materialization.check create mode 100644 test/files/run/macro-whitebox-fundep-materialization/Macros_1.scala create mode 100644 test/files/run/macro-whitebox-fundep-materialization/Test_2.scala delete mode 100644 test/files/run/t5923c.check create mode 100644 test/files/run/t5923c.scala delete mode 100644 test/files/run/t5923c/Macros_1.scala delete mode 100644 test/files/run/t5923c/Test_2.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index 57358f72f5..27920dbd74 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -678,7 +678,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers { // e.g. for Foo it will be Int :: String :: Boolean :: HNil), there's no way to convey this information // to the typechecker. Therefore the typechecker will infer Nothing for L, which is hardly what we want. // - // =========== THE SOLUTION =========== + // =========== THE SOLUTION (ENABLED ONLY FOR WHITEBOX MACROS) =========== // // To give materializers a chance to say their word before vanilla inference kicks in, // we infer as much as possible (e.g. in the example above even though L is hopeless, C still can be inferred to Foo) @@ -686,9 +686,12 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers { // Thanks to that the materializer can take a look at what's going on and react accordingly. val shouldInstantiate = typer.context.undetparams.nonEmpty && !mode.inPolyMode if (shouldInstantiate) { - forced += delayed - typer.infer.inferExprInstance(delayed, typer.context.extractUndetparams(), pt, keepNothings = false) - macroExpandApply(typer, delayed, mode, pt) + if (isBlackbox(expandee)) typer.instantiatePossiblyExpectingUnit(delayed, mode, pt) + else { + forced += delayed + typer.infer.inferExprInstance(delayed, typer.context.extractUndetparams(), pt, keepNothings = false) + macroExpandApply(typer, delayed, mode, pt) + } } else delayed } } diff --git a/test/files/neg/macro-blackbox-fundep-materialization.check b/test/files/neg/macro-blackbox-fundep-materialization.check new file mode 100644 index 0000000000..a5a9b9a206 --- /dev/null +++ b/test/files/neg/macro-blackbox-fundep-materialization.check @@ -0,0 +1,12 @@ +Test_2.scala:7: Iso.materializeIso is not a valid implicit value for Iso[Test.Foo,L] because: +hasMatchingSymbol reported error: type mismatch; + found : Iso[Test.Foo,(Int, String, Boolean)] + required: Iso[Test.Foo,Nothing] +Note: (Int, String, Boolean) >: Nothing, but trait Iso is invariant in type U. +You may wish to define U as -U instead. (SLS 4.5) + val equiv = foo(Foo(23, "foo", true)) + ^ +Test_2.scala:7: error: could not find implicit value for parameter iso: Iso[Test.Foo,L] + val equiv = foo(Foo(23, "foo", true)) + ^ +one error found diff --git a/test/files/neg/macro-blackbox-fundep-materialization.flags b/test/files/neg/macro-blackbox-fundep-materialization.flags new file mode 100644 index 0000000000..4c6cdb71e2 --- /dev/null +++ b/test/files/neg/macro-blackbox-fundep-materialization.flags @@ -0,0 +1 @@ +-Xlog-implicits \ No newline at end of file diff --git a/test/files/neg/macro-blackbox-fundep-materialization/Macros_1.scala b/test/files/neg/macro-blackbox-fundep-materialization/Macros_1.scala new file mode 100644 index 0000000000..6bddef4b9d --- /dev/null +++ b/test/files/neg/macro-blackbox-fundep-materialization/Macros_1.scala @@ -0,0 +1,39 @@ +import scala.language.experimental.macros +import scala.reflect.macros.BlackboxContext + +trait Iso[T, U] { + def to(t : T) : U + // def from(u : U) : T +} + +object Iso { + implicit def materializeIso[T, U]: Iso[T, U] = macro impl[T, U] + def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: BlackboxContext): c.Expr[Iso[T, U]] = { + import c.universe._ + import definitions._ + import Flag._ + + val sym = c.weakTypeOf[T].typeSymbol + if (!sym.isClass || !sym.asClass.isCaseClass) c.abort(c.enclosingPosition, s"$sym is not a case class") + val fields = sym.typeSignature.declarations.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + + def mkTpt() = { + val core = Ident(TupleClass(fields.length) orElse UnitClass) + if (fields.length == 0) core + else AppliedTypeTree(core, fields map (f => TypeTree(f.typeSignature))) + } + + def mkFrom() = { + if (fields.length == 0) Literal(Constant(Unit)) + else Apply(Ident(newTermName("Tuple" + fields.length)), fields map (f => Select(Ident(newTermName("f")), newTermName(f.name.toString.trim)))) + } + + val evidenceClass = ClassDef(Modifiers(FINAL), newTypeName("$anon"), List(), Template( + List(AppliedTypeTree(Ident(newTypeName("Iso")), List(Ident(sym), mkTpt()))), + emptyValDef, + List( + DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), List())), Literal(Constant(())))), + DefDef(Modifiers(), newTermName("to"), List(), List(List(ValDef(Modifiers(PARAM), newTermName("f"), Ident(sym), EmptyTree))), TypeTree(), mkFrom())))) + c.Expr[Iso[T, U]](Block(List(evidenceClass), Apply(Select(New(Ident(newTypeName("$anon"))), nme.CONSTRUCTOR), List()))) + } +} diff --git a/test/files/neg/macro-blackbox-fundep-materialization/Test_2.scala b/test/files/neg/macro-blackbox-fundep-materialization/Test_2.scala new file mode 100644 index 0000000000..a00f4ed7db --- /dev/null +++ b/test/files/neg/macro-blackbox-fundep-materialization/Test_2.scala @@ -0,0 +1,12 @@ +// see the comments for macroExpandApply.onDelayed for an explanation of what's tested here +object Test extends App { + case class Foo(i: Int, s: String, b: Boolean) + def foo[C, L](c: C)(implicit iso: Iso[C, L]): L = iso.to(c) + + { + val equiv = foo(Foo(23, "foo", true)) + def typed[T](t: => T) {} + typed[(Int, String, Boolean)](equiv) + println(equiv) + } +} \ No newline at end of file diff --git a/test/files/run/macro-blackbox-materialization.check b/test/files/run/macro-blackbox-materialization.check new file mode 100644 index 0000000000..7165b734ac --- /dev/null +++ b/test/files/run/macro-blackbox-materialization.check @@ -0,0 +1,3 @@ +C(Int) +C(String) +C(Nothing) diff --git a/test/files/run/macro-blackbox-materialization/Macros_1.scala b/test/files/run/macro-blackbox-materialization/Macros_1.scala new file mode 100644 index 0000000000..7c31dd7dc2 --- /dev/null +++ b/test/files/run/macro-blackbox-materialization/Macros_1.scala @@ -0,0 +1,16 @@ +// For the full version of the test, take a look at run/t5923a + +import scala.reflect.macros.BlackboxContext +import language.experimental.macros + +case class C[T](t: String) +object C { + implicit def foo[T]: C[T] = macro Macros.impl[T] +} + +object Macros { + def impl[T: c.WeakTypeTag](c: BlackboxContext) = { + import c.universe._ + reify(C[T](c.literal(weakTypeOf[T].toString).splice)) + } +} \ No newline at end of file diff --git a/test/files/run/macro-blackbox-materialization/Test_2.scala b/test/files/run/macro-blackbox-materialization/Test_2.scala new file mode 100644 index 0000000000..001ff9aea8 --- /dev/null +++ b/test/files/run/macro-blackbox-materialization/Test_2.scala @@ -0,0 +1,5 @@ +object Test extends App { + println(implicitly[C[Int]]) + println(implicitly[C[String]]) + println(implicitly[C[Nothing]]) +} \ No newline at end of file diff --git a/test/files/run/macro-whitebox-fundep-materialization.check b/test/files/run/macro-whitebox-fundep-materialization.check new file mode 100644 index 0000000000..bed7429108 --- /dev/null +++ b/test/files/run/macro-whitebox-fundep-materialization.check @@ -0,0 +1 @@ +(23,foo,true) diff --git a/test/files/run/macro-whitebox-fundep-materialization/Macros_1.scala b/test/files/run/macro-whitebox-fundep-materialization/Macros_1.scala new file mode 100644 index 0000000000..671a4fff4e --- /dev/null +++ b/test/files/run/macro-whitebox-fundep-materialization/Macros_1.scala @@ -0,0 +1,39 @@ +import scala.language.experimental.macros +import scala.reflect.macros.WhiteboxContext + +trait Iso[T, U] { + def to(t : T) : U + // def from(u : U) : T +} + +object Iso { + implicit def materializeIso[T, U]: Iso[T, U] = macro impl[T, U] + def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: WhiteboxContext): c.Expr[Iso[T, U]] = { + import c.universe._ + import definitions._ + import Flag._ + + val sym = c.weakTypeOf[T].typeSymbol + if (!sym.isClass || !sym.asClass.isCaseClass) c.abort(c.enclosingPosition, s"$sym is not a case class") + val fields = sym.typeSignature.declarations.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + + def mkTpt() = { + val core = Ident(TupleClass(fields.length) orElse UnitClass) + if (fields.length == 0) core + else AppliedTypeTree(core, fields map (f => TypeTree(f.typeSignature))) + } + + def mkFrom() = { + if (fields.length == 0) Literal(Constant(Unit)) + else Apply(Ident(newTermName("Tuple" + fields.length)), fields map (f => Select(Ident(newTermName("f")), newTermName(f.name.toString.trim)))) + } + + val evidenceClass = ClassDef(Modifiers(FINAL), newTypeName("$anon"), List(), Template( + List(AppliedTypeTree(Ident(newTypeName("Iso")), List(Ident(sym), mkTpt()))), + emptyValDef, + List( + DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), List())), Literal(Constant(())))), + DefDef(Modifiers(), newTermName("to"), List(), List(List(ValDef(Modifiers(PARAM), newTermName("f"), Ident(sym), EmptyTree))), TypeTree(), mkFrom())))) + c.Expr[Iso[T, U]](Block(List(evidenceClass), Apply(Select(New(Ident(newTypeName("$anon"))), nme.CONSTRUCTOR), List()))) + } +} diff --git a/test/files/run/macro-whitebox-fundep-materialization/Test_2.scala b/test/files/run/macro-whitebox-fundep-materialization/Test_2.scala new file mode 100644 index 0000000000..a00f4ed7db --- /dev/null +++ b/test/files/run/macro-whitebox-fundep-materialization/Test_2.scala @@ -0,0 +1,12 @@ +// see the comments for macroExpandApply.onDelayed for an explanation of what's tested here +object Test extends App { + case class Foo(i: Int, s: String, b: Boolean) + def foo[C, L](c: C)(implicit iso: Iso[C, L]): L = iso.to(c) + + { + val equiv = foo(Foo(23, "foo", true)) + def typed[T](t: => T) {} + typed[(Int, String, Boolean)](equiv) + println(equiv) + } +} \ No newline at end of file diff --git a/test/files/run/t5923c.check b/test/files/run/t5923c.check deleted file mode 100644 index bed7429108..0000000000 --- a/test/files/run/t5923c.check +++ /dev/null @@ -1 +0,0 @@ -(23,foo,true) diff --git a/test/files/run/t5923c.scala b/test/files/run/t5923c.scala new file mode 100644 index 0000000000..956b256785 --- /dev/null +++ b/test/files/run/t5923c.scala @@ -0,0 +1,4 @@ +// see neg/macro-blackbox-fundep-materialization and run/macro-whitebox-fundep-materialization +object Test extends App { + // do nothing +} \ No newline at end of file diff --git a/test/files/run/t5923c/Macros_1.scala b/test/files/run/t5923c/Macros_1.scala deleted file mode 100644 index c86e14966b..0000000000 --- a/test/files/run/t5923c/Macros_1.scala +++ /dev/null @@ -1,39 +0,0 @@ -import language.experimental.macros -import scala.reflect.macros.WhiteboxContext - -trait Iso[T, U] { - def to(t : T) : U - // def from(u : U) : T -} - -object Iso { - implicit def materializeIso[T, U]: Iso[T, U] = macro impl[T, U] - def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: WhiteboxContext): c.Expr[Iso[T, U]] = { - import c.universe._ - import definitions._ - import Flag._ - - val sym = c.weakTypeOf[T].typeSymbol - if (!sym.isClass || !sym.asClass.isCaseClass) c.abort(c.enclosingPosition, s"$sym is not a case class") - val fields = sym.typeSignature.declarations.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } - - def mkTpt() = { - val core = Ident(TupleClass(fields.length) orElse UnitClass) - if (fields.length == 0) core - else AppliedTypeTree(core, fields map (f => TypeTree(f.typeSignature))) - } - - def mkFrom() = { - if (fields.length == 0) Literal(Constant(Unit)) - else Apply(Ident(newTermName("Tuple" + fields.length)), fields map (f => Select(Ident(newTermName("f")), newTermName(f.name.toString.trim)))) - } - - val evidenceClass = ClassDef(Modifiers(FINAL), newTypeName("$anon"), List(), Template( - List(AppliedTypeTree(Ident(newTypeName("Iso")), List(Ident(sym), mkTpt()))), - emptyValDef, - List( - DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), List())), Literal(Constant(())))), - DefDef(Modifiers(), newTermName("to"), List(), List(List(ValDef(Modifiers(PARAM), newTermName("f"), Ident(sym), EmptyTree))), TypeTree(), mkFrom())))) - c.Expr[Iso[T, U]](Block(List(evidenceClass), Apply(Select(New(Ident(newTypeName("$anon"))), nme.CONSTRUCTOR), List()))) - } -} diff --git a/test/files/run/t5923c/Test_2.scala b/test/files/run/t5923c/Test_2.scala deleted file mode 100644 index a00f4ed7db..0000000000 --- a/test/files/run/t5923c/Test_2.scala +++ /dev/null @@ -1,12 +0,0 @@ -// see the comments for macroExpandApply.onDelayed for an explanation of what's tested here -object Test extends App { - case class Foo(i: Int, s: String, b: Boolean) - def foo[C, L](c: C)(implicit iso: Iso[C, L]): L = iso.to(c) - - { - val equiv = foo(Foo(23, "foo", true)) - def typed[T](t: => T) {} - typed[(Int, String, Boolean)](equiv) - println(equiv) - } -} \ No newline at end of file -- cgit v1.2.3 From 0d5c2f76ea30c6a45471dac635f035e931075453 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 2 Oct 2013 17:22:07 +0200 Subject: blackbox restriction #3: can't affect implicit search When an application of a blackbox macro is used as an implicit candidate, no expansion is performed until the macro is selected as the result of the implicit search. This makes it impossible to dynamically calculate availability of implicit macros. --- .../scala/tools/nsc/typechecker/Implicits.scala | 41 +++++++++++----------- src/reflect/scala/reflect/macros/Enclosures.scala | 12 ------- src/reflect/scala/reflect/macros/Typers.scala | 21 ----------- .../scala/reflect/macros/WhiteboxContext.scala | 33 +++++++++++++++++ .../macro-blackbox-dynamic-materialization.check | 4 +++ .../Macros_1.scala | 25 +++++++++++++ .../Test_2.scala | 4 +++ .../macro-blackbox-fundep-materialization.check | 6 +--- .../Impls_Macros_1.scala | 4 +-- .../run/macro-sip19-revised/Impls_Macros_1.scala | 4 +-- test/files/run/macro-sip19/Impls_Macros_1.scala | 4 +-- .../macro-whitebox-dynamic-materialization.check | 2 ++ .../Macros_1.scala | 25 +++++++++++++ .../Test_2.scala | 4 +++ 14 files changed, 125 insertions(+), 64 deletions(-) create mode 100644 test/files/neg/macro-blackbox-dynamic-materialization.check create mode 100644 test/files/neg/macro-blackbox-dynamic-materialization/Macros_1.scala create mode 100644 test/files/neg/macro-blackbox-dynamic-materialization/Test_2.scala create mode 100644 test/files/run/macro-whitebox-dynamic-materialization.check create mode 100644 test/files/run/macro-whitebox-dynamic-materialization/Macros_1.scala create mode 100644 test/files/run/macro-whitebox-dynamic-materialization/Test_2.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index c9dbdb93ff..01acbb8cc2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -596,7 +596,7 @@ trait Implicits { // workaround for deficient context provided by ModelFactoryImplicitSupport#makeImplicitConstraints val isScalaDoc = context.tree == EmptyTree - val itree = atPos(pos.focus) { + val itree0 = atPos(pos.focus) { if (isLocal && !isScalaDoc) { // SI-4270 SI-5376 Always use an unattributed Ident for implicits in the local scope, // rather than an attributed Select, to detect shadowing. @@ -608,15 +608,16 @@ trait Implicits { Select(gen.mkAttributedQualifier(info.pre), implicitMemberName) } } - typingLog("considering", typeDebug.ptTree(itree)) + val itree1 = if (isBlackbox(info.sym)) suppressMacroExpansion(itree0) else itree0 + typingLog("considering", typeDebug.ptTree(itree1)) - def fail(reason: String): SearchResult = failure(itree, reason) - def fallback = typed1(itree, EXPRmode, wildPt) + def fail(reason: String): SearchResult = failure(itree0, reason) + def fallback = typed1(itree1, EXPRmode, wildPt) try { - val itree1 = if (!isView) fallback else pt match { + val itree2 = if (!isView) fallback else pt match { case Function1(arg1, arg2) => typed1( - atPos(itree.pos)(Apply(itree, List(Ident("") setType approximate(arg1)))), + atPos(itree0.pos)(Apply(itree1, List(Ident("") setType approximate(arg1)))), EXPRmode, approximate(arg2) ) match { @@ -647,10 +648,10 @@ trait Implicits { if (Statistics.canEnable) Statistics.incCounter(typedImplicits) - val itree2 = if (isView) treeInfo.dissectApplied(itree1).callee - else adapt(itree1, EXPRmode, wildPt) + val itree3 = if (isView) treeInfo.dissectApplied(itree2).callee + else adapt(itree2, EXPRmode, wildPt) - typingStack.showAdapt(itree, itree2, pt, context) + typingStack.showAdapt(itree0, itree3, pt, context) def hasMatchingSymbol(tree: Tree): Boolean = (tree.symbol == info.sym) || { tree match { @@ -663,21 +664,21 @@ trait Implicits { if (context.hasErrors) fail("hasMatchingSymbol reported error: " + context.firstError.get.errMsg) - else if (isLocal && !hasMatchingSymbol(itree1)) + else if (isLocal && !hasMatchingSymbol(itree2)) fail("candidate implicit %s is shadowed by %s".format( - info.sym.fullLocationString, itree1.symbol.fullLocationString)) + info.sym.fullLocationString, itree2.symbol.fullLocationString)) else { val tvars = undetParams map freshVar def ptInstantiated = pt.instantiateTypeParams(undetParams, tvars) - if (matchesPt(itree2.tpe, ptInstantiated, undetParams)) { + if (matchesPt(itree3.tpe, ptInstantiated, undetParams)) { if (tvars.nonEmpty) typingLog("solve", ptLine("tvars" -> tvars, "tvars.constr" -> tvars.map(_.constr))) - val targs = solvedTypes(tvars, undetParams, undetParams map varianceInType(pt), upper = false, lubDepth(itree2.tpe :: pt :: Nil)) + val targs = solvedTypes(tvars, undetParams, undetParams map varianceInType(pt), upper = false, lubDepth(itree3.tpe :: pt :: Nil)) // #2421: check that we correctly instantiated type parameters outside of the implicit tree: - checkBounds(itree2, NoPrefix, NoSymbol, undetParams, targs, "inferred ") + checkBounds(itree3, NoPrefix, NoSymbol, undetParams, targs, "inferred ") context.firstError match { case Some(err) => return fail("type parameters weren't correctly instantiated outside of the implicit tree: " + err.errMsg) @@ -693,7 +694,7 @@ trait Implicits { if (okParams.isEmpty) EmptyTreeTypeSubstituter else { val subst = new TreeTypeSubstituter(okParams, okArgs) - subst traverse itree2 + subst traverse itree3 notifyUndetparamsInferred(okParams, okArgs) subst } @@ -711,9 +712,9 @@ trait Implicits { // This is just called for the side effect of error detection, // see SI-6966 to see what goes wrong if we use the result of this // as the SearchResult. - itree2 match { - case TypeApply(fun, args) => typedTypeApply(itree2, EXPRmode, fun, args) - case Apply(TypeApply(fun, args), _) => typedTypeApply(itree2, EXPRmode, fun, args) // t2421c + itree3 match { + case TypeApply(fun, args) => typedTypeApply(itree3, EXPRmode, fun, args) + case Apply(TypeApply(fun, args), _) => typedTypeApply(itree3, EXPRmode, fun, args) // t2421c case t => t } @@ -721,13 +722,13 @@ trait Implicits { case Some(err) => fail("typing TypeApply reported errors for the implicit tree: " + err.errMsg) case None => - val result = new SearchResult(itree2, subst) + val result = new SearchResult(unsuppressMacroExpansion(itree3), subst) if (Statistics.canEnable) Statistics.incCounter(foundImplicits) typingLog("success", s"inferred value of type $ptInstantiated is $result") result } } - else fail("incompatible: %s does not match expected type %s".format(itree2.tpe, ptInstantiated)) + else fail("incompatible: %s does not match expected type %s".format(itree3.tpe, ptInstantiated)) } } catch { diff --git a/src/reflect/scala/reflect/macros/Enclosures.scala b/src/reflect/scala/reflect/macros/Enclosures.scala index c3d019ccf3..31905c4739 100644 --- a/src/reflect/scala/reflect/macros/Enclosures.scala +++ b/src/reflect/scala/reflect/macros/Enclosures.scala @@ -45,18 +45,6 @@ trait Enclosures { */ def enclosingMacros: List[BlackboxContext] - /** Information about one of the currently considered implicit candidates. - * Candidates are used in plural form, because implicit parameters may themselves have implicit parameters, - * hence implicit searches can recursively trigger other implicit searches. - * - * Can be useful to get information about an application with an implicit parameter that is materialized during current macro expansion. - * If we're in an implicit macro being expanded, it's included in this list. - * - * Unlike `openImplicits`, this is a val, which means that it gets initialized when the context is created - * and always stays the same regardless of whatever happens during macro expansion. - */ - def enclosingImplicits: List[ImplicitCandidate] - /** Tries to guess a position for the enclosing application. * But that is simple, right? Just dereference `pos` of `macroApplication`? Not really. * If we're in a synthetic macro expansion (no positions), we must do our best to infer the position of something that triggerd this expansion. diff --git a/src/reflect/scala/reflect/macros/Typers.scala b/src/reflect/scala/reflect/macros/Typers.scala index ec90ee8fe6..29c1af110b 100644 --- a/src/reflect/scala/reflect/macros/Typers.scala +++ b/src/reflect/scala/reflect/macros/Typers.scala @@ -23,27 +23,6 @@ trait Typers { */ def openMacros: List[BlackboxContext] - /** Information about one of the currently considered implicit candidates. - * Candidates are used in plural form, because implicit parameters may themselves have implicit parameters, - * hence implicit searches can recursively trigger other implicit searches. - * - * `pre` and `sym` provide information about the candidate itself. - * `pt` and `tree` store the parameters of the implicit search the candidate is participating in. - */ - case class ImplicitCandidate(pre: Type, sym: Symbol, pt: Type, tree: Tree) - - /** Information about one of the currently considered implicit candidates. - * Candidates are used in plural form, because implicit parameters may themselves have implicit parameters, - * hence implicit searches can recursively trigger other implicit searches. - * - * Can be useful to get information about an application with an implicit parameter that is materialized during current macro expansion. - * If we're in an implicit macro being expanded, it's included in this list. - * - * Unlike `enclosingImplicits`, this is a def, which means that it gets recalculated on every invocation, - * so it might change depending on what is going on during macro expansion. - */ - def openImplicits: List[ImplicitCandidate] - /** Typechecks the provided tree against the expected type `pt` in the macro callsite context. * * If `silent` is false, `TypecheckException` will be thrown in case of a typecheck error. diff --git a/src/reflect/scala/reflect/macros/WhiteboxContext.scala b/src/reflect/scala/reflect/macros/WhiteboxContext.scala index 76bc17746c..9d65a5c16e 100644 --- a/src/reflect/scala/reflect/macros/WhiteboxContext.scala +++ b/src/reflect/scala/reflect/macros/WhiteboxContext.scala @@ -40,4 +40,37 @@ trait WhiteboxContext extends BlackboxContext { /** @inheritdoc */ def enclosingMacros: List[WhiteboxContext] + + /** Information about one of the currently considered implicit candidates. + * Candidates are used in plural form, because implicit parameters may themselves have implicit parameters, + * hence implicit searches can recursively trigger other implicit searches. + * + * `pre` and `sym` provide information about the candidate itself. + * `pt` and `tree` store the parameters of the implicit search the candidate is participating in. + */ + case class ImplicitCandidate(pre: Type, sym: Symbol, pt: Type, tree: Tree) + + /** Information about one of the currently considered implicit candidates. + * Candidates are used in plural form, because implicit parameters may themselves have implicit parameters, + * hence implicit searches can recursively trigger other implicit searches. + * + * Can be useful to get information about an application with an implicit parameter that is materialized during current macro expansion. + * If we're in an implicit macro being expanded, it's included in this list. + * + * Unlike `enclosingImplicits`, this is a def, which means that it gets recalculated on every invocation, + * so it might change depending on what is going on during macro expansion. + */ + def openImplicits: List[ImplicitCandidate] + + /** Information about one of the currently considered implicit candidates. + * Candidates are used in plural form, because implicit parameters may themselves have implicit parameters, + * hence implicit searches can recursively trigger other implicit searches. + * + * Can be useful to get information about an application with an implicit parameter that is materialized during current macro expansion. + * If we're in an implicit macro being expanded, it's included in this list. + * + * Unlike `openImplicits`, this is a val, which means that it gets initialized when the context is created + * and always stays the same regardless of whatever happens during macro expansion. + */ + def enclosingImplicits: List[ImplicitCandidate] } \ No newline at end of file diff --git a/test/files/neg/macro-blackbox-dynamic-materialization.check b/test/files/neg/macro-blackbox-dynamic-materialization.check new file mode 100644 index 0000000000..f6c73f7edb --- /dev/null +++ b/test/files/neg/macro-blackbox-dynamic-materialization.check @@ -0,0 +1,4 @@ +Test_2.scala:2: error: I don't like classes that contain integers + println(implicitly[Foo[C1]]) + ^ +one error found diff --git a/test/files/neg/macro-blackbox-dynamic-materialization/Macros_1.scala b/test/files/neg/macro-blackbox-dynamic-materialization/Macros_1.scala new file mode 100644 index 0000000000..a00d195005 --- /dev/null +++ b/test/files/neg/macro-blackbox-dynamic-materialization/Macros_1.scala @@ -0,0 +1,25 @@ +import scala.reflect.macros.BlackboxContext +import scala.language.experimental.macros + +trait Foo[T] + +class C1(val x: Int) +class C2(val x: String) + +trait LowPriority { + implicit def lessSpecific[T]: Foo[T] = null +} + +object Foo extends LowPriority { + implicit def moreSpecific[T]: Foo[T] = macro Macros.impl[T] +} + +object Macros { + def impl[T: c.WeakTypeTag](c: BlackboxContext) = { + import c.universe._ + val tpe = weakTypeOf[T] + if (tpe.members.exists(_.typeSignature =:= typeOf[Int])) + c.abort(c.enclosingPosition, "I don't like classes that contain integers") + q"new Foo[$tpe]{ override def toString = ${tpe.toString} }" + } +} \ No newline at end of file diff --git a/test/files/neg/macro-blackbox-dynamic-materialization/Test_2.scala b/test/files/neg/macro-blackbox-dynamic-materialization/Test_2.scala new file mode 100644 index 0000000000..bf19209ab7 --- /dev/null +++ b/test/files/neg/macro-blackbox-dynamic-materialization/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + println(implicitly[Foo[C1]]) + println(implicitly[Foo[C2]]) +} \ No newline at end of file diff --git a/test/files/neg/macro-blackbox-fundep-materialization.check b/test/files/neg/macro-blackbox-fundep-materialization.check index a5a9b9a206..3c03064a2d 100644 --- a/test/files/neg/macro-blackbox-fundep-materialization.check +++ b/test/files/neg/macro-blackbox-fundep-materialization.check @@ -1,12 +1,8 @@ -Test_2.scala:7: Iso.materializeIso is not a valid implicit value for Iso[Test.Foo,L] because: -hasMatchingSymbol reported error: type mismatch; +Test_2.scala:7: error: type mismatch; found : Iso[Test.Foo,(Int, String, Boolean)] required: Iso[Test.Foo,Nothing] Note: (Int, String, Boolean) >: Nothing, but trait Iso is invariant in type U. You may wish to define U as -U instead. (SLS 4.5) val equiv = foo(Foo(23, "foo", true)) ^ -Test_2.scala:7: error: could not find implicit value for parameter iso: Iso[Test.Foo,L] - val equiv = foo(Foo(23, "foo", true)) - ^ one error found diff --git a/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala b/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala index 23fcdd6445..9fb374800b 100644 --- a/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala +++ b/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala @@ -1,4 +1,4 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext import language.experimental.macros trait Complex[T] @@ -6,7 +6,7 @@ trait Complex[T] class Foo(val foo: Foo) object Complex { - def impl[T: c.WeakTypeTag](c: BlackboxContext): c.Expr[Complex[T]] = { + def impl[T: c.WeakTypeTag](c: WhiteboxContext): c.Expr[Complex[T]] = { import c.universe._ val tpe = weakTypeOf[T] for (f <- tpe.declarations.collect{case f: TermSymbol if f.isParamAccessor && !f.isMethod => f}) { diff --git a/test/files/run/macro-sip19-revised/Impls_Macros_1.scala b/test/files/run/macro-sip19-revised/Impls_Macros_1.scala index 870930c7e5..3acc52dbe0 100644 --- a/test/files/run/macro-sip19-revised/Impls_Macros_1.scala +++ b/test/files/run/macro-sip19-revised/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext object Macros { - def impl(c: BlackboxContext) = { + def impl(c: WhiteboxContext) = { import c.universe._ val inscope = c.inferImplicitValue(c.mirror.staticClass("SourceLocation").toType) diff --git a/test/files/run/macro-sip19/Impls_Macros_1.scala b/test/files/run/macro-sip19/Impls_Macros_1.scala index 72a3c2568d..f830d2af0d 100644 --- a/test/files/run/macro-sip19/Impls_Macros_1.scala +++ b/test/files/run/macro-sip19/Impls_Macros_1.scala @@ -1,7 +1,7 @@ -import scala.reflect.macros.BlackboxContext +import scala.reflect.macros.WhiteboxContext object Macros { - def impl(c: BlackboxContext) = { + def impl(c: WhiteboxContext) = { import c.universe._ val Apply(fun, args) = c.enclosingImplicits(0).tree val fileName = fun.pos.source.file.file.getName diff --git a/test/files/run/macro-whitebox-dynamic-materialization.check b/test/files/run/macro-whitebox-dynamic-materialization.check new file mode 100644 index 0000000000..ccec8e5b25 --- /dev/null +++ b/test/files/run/macro-whitebox-dynamic-materialization.check @@ -0,0 +1,2 @@ +null +C2 diff --git a/test/files/run/macro-whitebox-dynamic-materialization/Macros_1.scala b/test/files/run/macro-whitebox-dynamic-materialization/Macros_1.scala new file mode 100644 index 0000000000..87cd310b09 --- /dev/null +++ b/test/files/run/macro-whitebox-dynamic-materialization/Macros_1.scala @@ -0,0 +1,25 @@ +import scala.reflect.macros.WhiteboxContext +import scala.language.experimental.macros + +trait Foo[T] + +class C1(val x: Int) +class C2(val x: String) + +trait LowPriority { + implicit def lessSpecific[T]: Foo[T] = null +} + +object Foo extends LowPriority { + implicit def moreSpecific[T]: Foo[T] = macro Macros.impl[T] +} + +object Macros { + def impl[T: c.WeakTypeTag](c: WhiteboxContext) = { + import c.universe._ + val tpe = weakTypeOf[T] + if (tpe.members.exists(_.typeSignature =:= typeOf[Int])) + c.abort(c.enclosingPosition, "I don't like classes that contain integers") + q"new Foo[$tpe]{ override def toString = ${tpe.toString} }" + } +} \ No newline at end of file diff --git a/test/files/run/macro-whitebox-dynamic-materialization/Test_2.scala b/test/files/run/macro-whitebox-dynamic-materialization/Test_2.scala new file mode 100644 index 0000000000..bf19209ab7 --- /dev/null +++ b/test/files/run/macro-whitebox-dynamic-materialization/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + println(implicitly[Foo[C1]]) + println(implicitly[Foo[C2]]) +} \ No newline at end of file -- cgit v1.2.3 From f83296552aa80faf8a9350131c0448bc05b34c96 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 2 Oct 2013 17:22:17 +0200 Subject: blackbox restriction #4: can't customize pattern matching When an application of a blackbox macro is used as an extractor in a pattern match, it triggers an unconditional compiler error, preventing customizations of pattern matching implemented with macros. --- .../scala/tools/nsc/typechecker/PatternTypers.scala | 7 ++++--- test/files/neg/macro-blackbox-extractor.check | 4 ++++ .../neg/macro-blackbox-extractor/Macros_1.scala | 21 +++++++++++++++++++++ .../files/neg/macro-blackbox-extractor/Test_2.scala | 5 +++++ test/files/neg/t5903d.check | 2 +- test/files/run/macro-whitebox-extractor.check | 1 + .../run/macro-whitebox-extractor/Macros_1.scala | 21 +++++++++++++++++++++ .../files/run/macro-whitebox-extractor/Test_2.scala | 5 +++++ 8 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 test/files/neg/macro-blackbox-extractor.check create mode 100644 test/files/neg/macro-blackbox-extractor/Macros_1.scala create mode 100644 test/files/neg/macro-blackbox-extractor/Test_2.scala create mode 100644 test/files/run/macro-whitebox-extractor.check create mode 100644 test/files/run/macro-whitebox-extractor/Macros_1.scala create mode 100644 test/files/run/macro-whitebox-extractor/Test_2.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala b/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala index f69b8a9697..ba135d7d25 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala @@ -409,9 +409,10 @@ trait PatternTypers { if (fun1.tpe.isErroneous) duplErrTree - else if (unapplyMethod.isMacro && !fun1.isInstanceOf[Apply]) - duplErrorTree(WrongShapeExtractorExpansion(tree)) - else + else if (unapplyMethod.isMacro && !fun1.isInstanceOf[Apply]) { + if (isBlackbox(unapplyMethod)) duplErrorTree(BlackboxExtractorExpansion(tree)) + else duplErrorTree(WrongShapeExtractorExpansion(tree)) + } else makeTypedUnApply() } diff --git a/test/files/neg/macro-blackbox-extractor.check b/test/files/neg/macro-blackbox-extractor.check new file mode 100644 index 0000000000..4c53ff19b8 --- /dev/null +++ b/test/files/neg/macro-blackbox-extractor.check @@ -0,0 +1,4 @@ +Test_2.scala:3: error: extractor macros can only be whitebox + case Extractor(x) => println(x) + ^ +one error found diff --git a/test/files/neg/macro-blackbox-extractor/Macros_1.scala b/test/files/neg/macro-blackbox-extractor/Macros_1.scala new file mode 100644 index 0000000000..5c7748bec9 --- /dev/null +++ b/test/files/neg/macro-blackbox-extractor/Macros_1.scala @@ -0,0 +1,21 @@ +import scala.reflect.macros.BlackboxContext +import language.experimental.macros + +object Extractor { + def unapply(x: Int) = macro Macros.unapplyImpl +} + +object Macros { + def unapplyImpl(c: BlackboxContext)(x: c.Tree) = { + import c.universe._ + q""" + new { + class Match(x: Int) { + def isEmpty = false + def get = x + } + def unapply(x: Int) = new Match(x) + }.unapply($x) + """ + } +} diff --git a/test/files/neg/macro-blackbox-extractor/Test_2.scala b/test/files/neg/macro-blackbox-extractor/Test_2.scala new file mode 100644 index 0000000000..41be6f9767 --- /dev/null +++ b/test/files/neg/macro-blackbox-extractor/Test_2.scala @@ -0,0 +1,5 @@ +object Test extends App { + 42 match { + case Extractor(x) => println(x) + } +} diff --git a/test/files/neg/t5903d.check b/test/files/neg/t5903d.check index 9b8526b7f5..54a91a7ba6 100644 --- a/test/files/neg/t5903d.check +++ b/test/files/neg/t5903d.check @@ -1,4 +1,4 @@ -Test_2.scala:4: error: extractor macros can only expand into extractor calls +Test_2.scala:4: error: extractor macros can only be whitebox case t"$x" => println(x) ^ one error found diff --git a/test/files/run/macro-whitebox-extractor.check b/test/files/run/macro-whitebox-extractor.check new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/test/files/run/macro-whitebox-extractor.check @@ -0,0 +1 @@ +42 diff --git a/test/files/run/macro-whitebox-extractor/Macros_1.scala b/test/files/run/macro-whitebox-extractor/Macros_1.scala new file mode 100644 index 0000000000..4a1138fc9d --- /dev/null +++ b/test/files/run/macro-whitebox-extractor/Macros_1.scala @@ -0,0 +1,21 @@ +import scala.reflect.macros.WhiteboxContext +import language.experimental.macros + +object Extractor { + def unapply(x: Int) = macro Macros.unapplyImpl +} + +object Macros { + def unapplyImpl(c: WhiteboxContext)(x: c.Tree) = { + import c.universe._ + q""" + new { + class Match(x: Int) { + def isEmpty = false + def get = x + } + def unapply(x: Int) = new Match(x) + }.unapply($x) + """ + } +} diff --git a/test/files/run/macro-whitebox-extractor/Test_2.scala b/test/files/run/macro-whitebox-extractor/Test_2.scala new file mode 100644 index 0000000000..41be6f9767 --- /dev/null +++ b/test/files/run/macro-whitebox-extractor/Test_2.scala @@ -0,0 +1,5 @@ +object Test extends App { + 42 match { + case Extractor(x) => println(x) + } +} -- cgit v1.2.3