Skip to content

Rename scala.quoted.Reporting to report #9380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\"...\"`")
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion library/src-bootstrapped/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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

}
2 changes: 1 addition & 1 deletion tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
2 changes: 1 addition & 1 deletion tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)})}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i9014/Macros_1.scala
Original file line number Diff line number Diff line change
@@ -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!")
2 changes: 1 addition & 1 deletion tests/neg-macros/quote-error-2/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"); '{ ??? } }

}
2 changes: 1 addition & 1 deletion tests/neg-macros/quote-error/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"); '{ ??? } }
}
2 changes: 1 addition & 1 deletion tests/neg-staging/i5941/macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)`")
'{???}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)})}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
2 changes: 1 addition & 1 deletion tests/run-macros/f-interpolation-1/FQuote_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 '{???}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/run-macros/i5941/macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)`")
'{???}
}
}
Expand Down Expand Up @@ -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 '{???}
}

Expand All @@ -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
Expand All @@ -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 '{???}
}

Expand All @@ -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")
'{???}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/i8671/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

2 changes: 1 addition & 1 deletion tests/run-macros/quote-matcher-symantics-3/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
'{ ??? }

})
Expand Down
8 changes: 4 additions & 4 deletions tests/run-macros/refined-selectable-macro/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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, ("<error>", defn.AnyType))
}
}
Expand All @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/string-context-implicits/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
'{???}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/tasty-interpolation-1/Macro.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import scala.quoted._
import scala.language.implicitConversions
import scala.quoted.Reporting.error
import scala.quoted.report.error

object Macro {

Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/tasty-macro-const/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/xml-interpolation-1/XmlQuote_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 '{ ??? }
}

Expand Down
6 changes: 3 additions & 3 deletions tests/run-macros/xml-interpolation-2/XmlQuote_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 '{???}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-staging/staged-tuples/StagedTuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
}
Expand Down