From 1bfc467f67dedafabf5f94f5f3df18c320c16341 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 17 Jul 2020 11:42:42 +0200 Subject: [PATCH] Rename `scala.quoted.Reporting` to `report` --- .../src/dotty/tools/dotc/transform/Splicer.scala | 4 ++-- .../dotty/internal/CompileTimeMacros.scala | 2 +- .../dotty/internal/StringContextMacro.scala | 4 ++-- library/src-bootstrapped/scala/quoted/Expr.scala | 2 +- .../scala/quoted/{Reporting.scala => report.scala} | 7 +++++-- .../scala/quoted/{Reporting.scala => report.scala} | 5 +---- .../BigFloat/BigFloatFromDigitsImpl_1.scala | 2 +- .../GenericNumLits/EvenFromDigitsImpl_1.scala | 2 +- tests/neg-macros/i9014/Macros_1.scala | 2 +- tests/neg-macros/quote-error-2/Macro_1.scala | 2 +- tests/neg-macros/quote-error/Macro_1.scala | 2 +- tests/neg-staging/i5941/macro_1.scala | 2 +- .../GenericNumLits/EvenFromDigitsImpl_1.scala | 2 +- .../BigFloat/BigFloatFromDigitsImpl_1.scala | 2 +- tests/run-macros/f-interpolation-1/FQuote_1.scala | 2 +- tests/run-macros/i5941/macro_1.scala | 12 ++++++------ tests/run-macros/i8671/Macro_1.scala | 4 ++-- .../quote-matcher-symantics-3/quoted_1.scala | 2 +- .../refined-selectable-macro/Macro_1.scala | 8 ++++---- .../string-context-implicits/Macro_1.scala | 4 ++-- tests/run-macros/tasty-interpolation-1/Macro.scala | 2 +- tests/run-macros/tasty-macro-const/quoted_1.scala | 4 ++-- .../run-macros/xml-interpolation-1/XmlQuote_1.scala | 2 +- .../run-macros/xml-interpolation-2/XmlQuote_1.scala | 6 +++--- tests/run-staging/staged-tuples/StagedTuple.scala | 2 +- 25 files changed, 44 insertions(+), 44 deletions(-) rename library/src-bootstrapped/scala/quoted/{Reporting.scala => report.scala} (92%) rename library/src-non-bootstrapped/scala/quoted/{Reporting.scala => report.scala} (86%) diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index 1efe4ec513b0..42c09b2ae3a1 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -54,7 +54,7 @@ object Splicer { catch { case ex: CompilationUnit.SuspendException => throw ex - case ex: scala.quoted.Reporting.StopQuotedContext if ctx.reporter.hasErrors => + case ex: scala.quoted.report.StopQuotedContext if ctx.reporter.hasErrors => // errors have been emitted EmptyTree case ex: StopInterpretation => @@ -391,7 +391,7 @@ object Splicer { throw new StopInterpretation(sw.toString, pos) case ex: InvocationTargetException => ex.getTargetException match { - case ex: scala.quoted.Reporting.StopQuotedContext => + case ex: scala.quoted.report.StopQuotedContext => throw ex case MissingClassDefinedInCurrentRun(sym) if ctx.compilationUnit.isSuspendable => if (ctx.settings.XprintSuspension.value) diff --git a/library/src-bootstrapped/dotty/internal/CompileTimeMacros.scala b/library/src-bootstrapped/dotty/internal/CompileTimeMacros.scala index f30a53a23c24..2e2d0cc6f224 100644 --- a/library/src-bootstrapped/dotty/internal/CompileTimeMacros.scala +++ b/library/src-bootstrapped/dotty/internal/CompileTimeMacros.scala @@ -8,4 +8,4 @@ object CompileTimeMacros: case (Expr.StringContext(Consts(parts)), Varargs(args2)) => Expr(StringContext(parts: _*).s(args2.map(_.show): _*)) case _ => - Reporting.throwError("compiletime.code must be used as a string interpolator `code\"...\"`") + report.throwError("compiletime.code must be used as a string interpolator `code\"...\"`") diff --git a/library/src-bootstrapped/dotty/internal/StringContextMacro.scala b/library/src-bootstrapped/dotty/internal/StringContextMacro.scala index 5b7a06877b9a..84dcbf96c837 100644 --- a/library/src-bootstrapped/dotty/internal/StringContextMacro.scala +++ b/library/src-bootstrapped/dotty/internal/StringContextMacro.scala @@ -63,12 +63,12 @@ object StringContextMacro { val (partsExpr, parts) = strCtxExpr match { case Expr.StringContext(p1 @ Consts(p2)) => (p1.toList, p2.toList) - case _ => Reporting.throwError("Expected statically known String Context", strCtxExpr) + case _ => report.throwError("Expected statically known String Context", strCtxExpr) } val args = argsExpr match { case Varargs(args) => args - case _ => Reporting.throwError("Expected statically known argument list", argsExpr) + case _ => report.throwError("Expected statically known argument list", argsExpr) } val reporter = new Reporter{ diff --git a/library/src-bootstrapped/scala/quoted/Expr.scala b/library/src-bootstrapped/scala/quoted/Expr.scala index 852b80b3e552..14fc037169f5 100644 --- a/library/src-bootstrapped/scala/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/quoted/Expr.scala @@ -27,7 +27,7 @@ abstract class Expr[+T] private[scala] { * Otherwise returns the value. */ final def unliftOrError[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): U = - unlift(this).getOrElse(Reporting.throwError(s"Expected a known value. \n\nThe value of: $show\ncould not be unlifted using $unlift", this)) + unlift(this).getOrElse(report.throwError(s"Expected a known value. \n\nThe value of: $show\ncould not be unlifted using $unlift", this)) /** Pattern matches `this` against `that`. Effectively performing a deep equality check. * It does the equivalent of diff --git a/library/src-bootstrapped/scala/quoted/Reporting.scala b/library/src-bootstrapped/scala/quoted/report.scala similarity index 92% rename from library/src-bootstrapped/scala/quoted/Reporting.scala rename to library/src-bootstrapped/scala/quoted/report.scala index 82b9254a66e6..9a2bedb409b7 100644 --- a/library/src-bootstrapped/scala/quoted/Reporting.scala +++ b/library/src-bootstrapped/scala/quoted/report.scala @@ -1,6 +1,6 @@ package scala.quoted -object Reporting { +object report: /** Report an error at the position of the macro expansion */ def error(msg: => String)(using qctx: QuoteContext): Unit = @@ -32,4 +32,7 @@ object Reporting { /** Throwable used to stop the expansion of a macro after an error was reported */ class StopQuotedContext extends Throwable -} +end report + +@deprecated("Use scala.quoted.report", "") +def Reporting: report.type = report diff --git a/library/src-non-bootstrapped/scala/quoted/Reporting.scala b/library/src-non-bootstrapped/scala/quoted/report.scala similarity index 86% rename from library/src-non-bootstrapped/scala/quoted/Reporting.scala rename to library/src-non-bootstrapped/scala/quoted/report.scala index 4e5fe83fe529..d20990ba9f5a 100644 --- a/library/src-non-bootstrapped/scala/quoted/Reporting.scala +++ b/library/src-non-bootstrapped/scala/quoted/report.scala @@ -1,8 +1,5 @@ package scala.quoted -object Reporting { - +object report: /** Throwable used to stop the expansion of a macro after an error was reported */ class StopQuotedContext extends Throwable - -} diff --git a/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala b/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala index c24bf5e9339a..7f29fdc2505a 100644 --- a/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala +++ b/tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala @@ -10,7 +10,7 @@ object BigFloatFromDigitsImpl: val BigFloat(m, e) = BigFloat(ds) '{BigFloat(${Expr(m)}, ${Expr(e)})} catch case ex: FromDigits.FromDigitsException => - Reporting.error(ex.getMessage) + report.error(ex.getMessage) '{BigFloat(0, 0)} case digits => '{BigFloat($digits)} diff --git a/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala b/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala index 5a54476dc756..3c618e583c8e 100644 --- a/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala +++ b/tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala @@ -9,7 +9,7 @@ object EvenFromDigitsImpl: try evenFromDigits(ds) catch { case ex: FromDigits.FromDigitsException => - Reporting.error(ex.getMessage) + report.error(ex.getMessage) Even(0) } '{Even(${Expr(ev.n)})} diff --git a/tests/neg-macros/i9014/Macros_1.scala b/tests/neg-macros/i9014/Macros_1.scala index f14bbe9c98a6..2f1d4250cdca 100644 --- a/tests/neg-macros/i9014/Macros_1.scala +++ b/tests/neg-macros/i9014/Macros_1.scala @@ -1,4 +1,4 @@ import scala.quoted._ trait Bar inline given as Bar = ${ impl } -def impl(using qctx: QuoteContext): Expr[Bar] = Reporting.throwError("Failed to expand!") +def impl(using qctx: QuoteContext): Expr[Bar] = report.throwError("Failed to expand!") diff --git a/tests/neg-macros/quote-error-2/Macro_1.scala b/tests/neg-macros/quote-error-2/Macro_1.scala index 4b3ed471f4a1..9afe78f87bfc 100644 --- a/tests/neg-macros/quote-error-2/Macro_1.scala +++ b/tests/neg-macros/quote-error-2/Macro_1.scala @@ -7,6 +7,6 @@ object Macro_1 { def msg(b: Boolean)(using qctx: QuoteContext): Expr[String] = if (b) '{"foo(true)"} - else { Reporting.error("foo cannot be called with false"); '{ ??? } } + else { report.error("foo cannot be called with false"); '{ ??? } } } diff --git a/tests/neg-macros/quote-error/Macro_1.scala b/tests/neg-macros/quote-error/Macro_1.scala index a9a605fc9d6b..6ab431895c09 100644 --- a/tests/neg-macros/quote-error/Macro_1.scala +++ b/tests/neg-macros/quote-error/Macro_1.scala @@ -4,5 +4,5 @@ object Macro_1 { inline def foo(inline b: Boolean): Unit = ${fooImpl('b)} def fooImpl(b: Expr[Boolean])(using qctx: QuoteContext) : Expr[Unit] = if (b.unliftOrError) '{println("foo(true)")} - else { Reporting.error("foo cannot be called with false"); '{ ??? } } + else { report.error("foo cannot be called with false"); '{ ??? } } } diff --git a/tests/neg-staging/i5941/macro_1.scala b/tests/neg-staging/i5941/macro_1.scala index 5c32dc801d70..856ecdb53db9 100644 --- a/tests/neg-staging/i5941/macro_1.scala +++ b/tests/neg-staging/i5941/macro_1.scala @@ -33,7 +33,7 @@ object Lens { apply($getter)(setter) } case _ => - Reporting.error("Unsupported syntax. Example: `GenLens[Address](_.streetNumber)`") + report.error("Unsupported syntax. Example: `GenLens[Address](_.streetNumber)`") '{???} } } diff --git a/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala b/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala index 5a54476dc756..3c618e583c8e 100644 --- a/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala +++ b/tests/neg-with-compiler/GenericNumLits/EvenFromDigitsImpl_1.scala @@ -9,7 +9,7 @@ object EvenFromDigitsImpl: try evenFromDigits(ds) catch { case ex: FromDigits.FromDigitsException => - Reporting.error(ex.getMessage) + report.error(ex.getMessage) Even(0) } '{Even(${Expr(ev.n)})} diff --git a/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala b/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala index c24bf5e9339a..7f29fdc2505a 100644 --- a/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala +++ b/tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala @@ -10,7 +10,7 @@ object BigFloatFromDigitsImpl: val BigFloat(m, e) = BigFloat(ds) '{BigFloat(${Expr(m)}, ${Expr(e)})} catch case ex: FromDigits.FromDigitsException => - Reporting.error(ex.getMessage) + report.error(ex.getMessage) '{BigFloat(0, 0)} case digits => '{BigFloat($digits)} diff --git a/tests/run-macros/f-interpolation-1/FQuote_1.scala b/tests/run-macros/f-interpolation-1/FQuote_1.scala index 715ce47fea8f..730b7630b53e 100644 --- a/tests/run-macros/f-interpolation-1/FQuote_1.scala +++ b/tests/run-macros/f-interpolation-1/FQuote_1.scala @@ -38,7 +38,7 @@ object FQuote { values.forall(isStringConstant) => values.collect { case Literal(Constant(value: String)) => value } case tree => - Reporting.error(s"String literal expected, but ${tree.showExtractors} found") + report.error(s"String literal expected, but ${tree.showExtractors} found") return '{???} } diff --git a/tests/run-macros/i5941/macro_1.scala b/tests/run-macros/i5941/macro_1.scala index 073302f648ac..467203dd8957 100644 --- a/tests/run-macros/i5941/macro_1.scala +++ b/tests/run-macros/i5941/macro_1.scala @@ -53,7 +53,7 @@ object Lens { apply($getter)(setter) } case _ => - Reporting.error("Unsupported syntax. Example: `GenLens[Address](_.streetNumber)`") + report.error("Unsupported syntax. Example: `GenLens[Address](_.streetNumber)`") '{???} } } @@ -95,7 +95,7 @@ object Iso { // 2. A must be a tuple // 3. The parameters of S must match A if (tpS.classSymbol.flatMap(cls => if (cls.flags.is(Flags.Case)) Some(true) else None).isEmpty) { - Reporting.error("Only support generation for case classes") + report.error("Only support generation for case classes") return '{???} } @@ -106,13 +106,13 @@ object Iso { } if (cls.caseFields.size != 1) { - Reporting.error("Use GenIso.fields for case classes more than one parameter") + report.error("Use GenIso.fields for case classes more than one parameter") return '{???} } val fieldTp = tpS.memberType(cls.caseFields.head) if (!(fieldTp =:= tpA)) { - Reporting.error(s"The type of case class field $fieldTp does not match $tpA") + report.error(s"The type of case class field $fieldTp does not match $tpA") '{???} } else '{ // (p: S) => p._1 @@ -139,7 +139,7 @@ object Iso { val cls = tpS.classSymbol.get if (cls.caseFields.size != 0) { - Reporting.error("Use GenIso.fields for case classes more than one parameter") + report.error("Use GenIso.fields for case classes more than one parameter") return '{???} } @@ -154,7 +154,7 @@ object Iso { } } else { - Reporting.error("Only support generation for case classes or singleton types") + report.error("Only support generation for case classes or singleton types") '{???} } } diff --git a/tests/run-macros/i8671/Macro_1.scala b/tests/run-macros/i8671/Macro_1.scala index 8de729f001d8..92a36a82b844 100644 --- a/tests/run-macros/i8671/Macro_1.scala +++ b/tests/run-macros/i8671/Macro_1.scala @@ -18,11 +18,11 @@ object FileName { case Right(fn) => '{FileName.unsafe(${Expr(fn.name)})} // Or `Expr(fn)` if there is a `Liftable[FileName]` case Left(_) => - Reporting.throwError(s"$s is not a valid file name! It must not contain a /", fileName) + report.throwError(s"$s is not a valid file name! It must not contain a /", fileName) } case _ => - Reporting.throwError(s"$fileName is not a valid file name. It must be a literal string", fileName) + report.throwError(s"$fileName is not a valid file name. It must be a literal string", fileName) } } diff --git a/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala index 55a1b9aa5154..33984a6ef4dc 100644 --- a/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala @@ -66,7 +66,7 @@ object Macros { case FromEnv(expr) => expr.asInstanceOf[Expr[R[T]]] case _ => - Reporting.error("Expected explicit value but got: " + e.show, e) + report.error("Expected explicit value but got: " + e.show, e) '{ ??? } }) diff --git a/tests/run-macros/refined-selectable-macro/Macro_1.scala b/tests/run-macros/refined-selectable-macro/Macro_1.scala index bf4f64bce9f1..e97e6b50abe5 100644 --- a/tests/run-macros/refined-selectable-macro/Macro_1.scala +++ b/tests/run-macros/refined-selectable-macro/Macro_1.scala @@ -26,7 +26,7 @@ object Macro { case _: TypeBounds => rec(parent) case _: MethodType | _: PolyType | _: TypeBounds | _: ByNameType => - Reporting.warning(s"Ignored `$name` as a field of the record", s) + report.warning(s"Ignored `$name` as a field of the record", s) rec(parent) case info: Type => (name, info) :: rec(parent) @@ -60,10 +60,10 @@ object Macro { // Tuple2(S, T) where S must be a constant string type case AppliedType(parent, ConstantType(Constant(name: String)) :: (info: Type) :: Nil) if (parent.typeSymbol == defn.TupleClass(2)) => if seen(name) then - Reporting.error(s"Repeated record name: $name", s) + report.error(s"Repeated record name: $name", s) (seen + name, (name, info)) case _ => - Reporting.error("Tuple type was not explicit expected `(S, T)` where S is a singleton string", s) + report.error("Tuple type was not explicit expected `(S, T)` where S is a singleton string", s) (seen, ("", defn.AnyType)) } } @@ -82,7 +82,7 @@ object Macro { })._2 // Tuple case _ => - Reporting.error("Tuple type must be of known size", s) + report.error("Tuple type must be of known size", s) Nil } } diff --git a/tests/run-macros/string-context-implicits/Macro_1.scala b/tests/run-macros/string-context-implicits/Macro_1.scala index 877686ba2d9e..800b44856397 100644 --- a/tests/run-macros/string-context-implicits/Macro_1.scala +++ b/tests/run-macros/string-context-implicits/Macro_1.scala @@ -11,14 +11,14 @@ private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using val showTp = '[Show[$tp]] Expr.summon(using showTp) match { case Some(showExpr) => '{ $showExpr.show($arg) } - case None => Reporting.error(s"could not find implicit for ${showTp.show}", arg); '{???} + case None => report.error(s"could not find implicit for ${showTp.show}", arg); '{???} } } val newArgsExpr = Varargs(argShowedExprs) '{ $sc.s($newArgsExpr: _*) } case _ => // `new StringContext(...).showMeExpr(args: _*)` not an explicit `showMeExpr"..."` - Reporting.error(s"Args must be explicit", argsExpr) + report.error(s"Args must be explicit", argsExpr) '{???} } } diff --git a/tests/run-macros/tasty-interpolation-1/Macro.scala b/tests/run-macros/tasty-interpolation-1/Macro.scala index 183b44ab01d5..7d82843b563a 100644 --- a/tests/run-macros/tasty-interpolation-1/Macro.scala +++ b/tests/run-macros/tasty-interpolation-1/Macro.scala @@ -1,7 +1,7 @@ import scala.quoted._ import scala.language.implicitConversions -import scala.quoted.Reporting.error +import scala.quoted.report.error object Macro { diff --git a/tests/run-macros/tasty-macro-const/quoted_1.scala b/tests/run-macros/tasty-macro-const/quoted_1.scala index a685480d4fa1..2068f5565fde 100644 --- a/tests/run-macros/tasty-macro-const/quoted_1.scala +++ b/tests/run-macros/tasty-macro-const/quoted_1.scala @@ -10,13 +10,13 @@ object Macros { xTree match { case Inlined(_, _, Literal(Constant(n: Int))) => if (n <= 0) { - Reporting.error("Parameter must be natural number") + report.error("Parameter must be natural number") '{0} } else { xTree.seal.cast[Int] } case _ => - Reporting.error("Parameter must be a known constant") + report.error("Parameter must be a known constant") '{0} } } diff --git a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala index 43c0e0736cfc..6d495df0cad2 100644 --- a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala @@ -48,7 +48,7 @@ object XmlQuote { values.forall(isStringConstant) => values.collect { case Literal(Constant(value: String)) => value } case tree => - Reporting.error(s"String literal expected, but ${tree.showExtractors} found") + report.error(s"String literal expected, but ${tree.showExtractors} found") return '{ ??? } } diff --git a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala index 6a055c9f1b80..1a19cf143168 100644 --- a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala @@ -43,15 +43,15 @@ object XmlQuote { values.iterator.map { case Literal(Constant(value: String)) => value case _ => - Reporting.error("Expected statically known String") + report.error("Expected statically known String") return '{???} }.toList case _ => - Reporting.error("Expected statically known StringContext") + report.error("Expected statically known StringContext") return '{???} } case _ => - Reporting.error("Expected statically known SCOps") + report.error("Expected statically known SCOps") return '{???} } diff --git a/tests/run-staging/staged-tuples/StagedTuple.scala b/tests/run-staging/staged-tuples/StagedTuple.scala index 72a4d7697ad3..9640a0640e81 100644 --- a/tests/run-staging/staged-tuples/StagedTuple.scala +++ b/tests/run-staging/staged-tuples/StagedTuple.scala @@ -132,7 +132,7 @@ object StagedTuple { else { def fallbackApply(): Expr[Elem[Tup, N]] = nValue match { case Some(n) => - Reporting.error("index out of bounds: " + n, tup) + report.error("index out of bounds: " + n, tup) '{ throw new IndexOutOfBoundsException(${Expr(n.toString)}) } case None => '{scala.runtime.Tuple.apply($tup, $n)}.as[Elem[Tup, N]] }