Skip to content

Unify quoted.report and reflect.Reporting #10474

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
Nov 26, 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
42 changes: 36 additions & 6 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2541,19 +2541,49 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def path: java.nio.file.Path = ctx.compilationUnit.source.file.jpath
end Source

object Reporting extends ReportingModule:
def error(msg: => String, pos: Position): Unit =
object report extends ReportModule:

def error(msg: String): Unit =
dotc.report.error(msg, Position.ofMacroExpansion)

def error(msg: String, expr: Expr[Any]): Unit =
dotc.report.error(msg, Term.of(expr).pos)

def error(msg: String, pos: Position): Unit =
dotc.report.error(msg, pos)

def error(msg: => String, sourceFile: SourceFile, start: Int, end: Int): Unit =
def error(msg: String, sourceFile: SourceFile, start: Int, end: Int): Unit =
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))

def warning(msg: => String, pos: Position): Unit =
def throwError(msg: String): Nothing =
error(msg)
throw new scala.quoted.runtime.StopMacroExpansion

def throwError(msg: String, expr: Expr[Any]): Nothing =
error(msg, expr)
throw new scala.quoted.runtime.StopMacroExpansion

def throwError(msg: String, pos: Position): Nothing =
error(msg, pos)
throw new scala.quoted.runtime.StopMacroExpansion

def throwError(msg: String, sourceFile: SourceFile, start: Int, end: Int): Nothing =
error(msg, sourceFile, start, end)
throw new scala.quoted.runtime.StopMacroExpansion

def warning(msg: String): Unit =
dotc.report.warning(msg, Position.ofMacroExpansion)

def warning(msg: String, expr: Expr[Any]): Unit =
dotc.report.warning(msg, Term.of(expr).pos)

def warning(msg: String, pos: Position): Unit =
dotc.report.warning(msg, pos)

def warning(msg: => String, sourceFile: SourceFile, start: Int, end: Int): Unit =
def warning(msg: String, sourceFile: SourceFile, start: Int, end: Int): Unit =
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))
end Reporting

end report

type Documentation = dotc.core.Comments.Comment

Expand Down
53 changes: 38 additions & 15 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
def unliftOrError(using Unliftable[T]): T =
def reportError =
val msg = s"Expected a known value. \n\nThe value of: ${self.show}\ncould not be unlifted using $unlift"
report.throwError(msg, self)(using Quotes.this)
reflect.report.throwError(msg, self)
summon[Unliftable[T]].fromExpr(self)(using Quotes.this).getOrElse(reportError)

end extension
Expand Down Expand Up @@ -3381,24 +3381,47 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
// REPORTING //
///////////////

val Reporting: ReportingModule
val report: ReportModule

/** Module containg error and waring reporiting.
*
* Also see scala.quoted.report
*/
trait ReportingModule { self: Reporting.type =>
/** Emits an error message */
def error(msg: => String, pos: Position): Unit
/** Module containg error and waring reporiting. */
trait ReportModule { self: report.type =>

/** Report an error at the position of the macro expansion */
def error(msg: String): Unit

/** Report an error at the position of `expr` */
def error(msg: String, expr: Expr[Any]): Unit

/** Report an error message at the given position */
def error(msg: String, pos: Position): Unit

/** Report an error at a specific range of a file. The positions must be contained in the file. */
def error(msg: String, source: SourceFile, start: Int, end: Int): Unit

/** Report an error at the position of the macro expansion and throws a StopMacroExpansion */
def throwError(msg: String): Nothing

/** Report an error at the position of `expr` */
def throwError(msg: String, expr: Expr[Any]): Nothing

/** Report an error message at the given position and throws a StopMacroExpansion */
def throwError(msg: String, pos: Position): Nothing

/** Report an error at a specific range of a file and throws a StopMacroExpansion. The positions must be contained in the file. */
def throwError(msg: String, source: SourceFile, start: Int, end: Int): Nothing

/** Report a warning at the position of the macro expansion */
def warning(msg: String): Unit

/** Report a warning at the on the position of `expr` */
def warning(msg: String, expr: Expr[Any]): Unit

/** Emits an error at a specific range of a file */
def error(msg: => String, source: SourceFile, start: Int, end: Int): Unit
/** Report an warning message at the given position */
def warning(msg: String, pos: Position): Unit

/** Emits an error message */
def warning(msg: => String, pos: Position): Unit
/** Emits a warning at a specific range of a file. The positions must be contained in the file. */
def warning(msg: String, source: SourceFile, start: Int, end: Int): Unit

/** Emits a warning at a specific range of a file */
def warning(msg: => String, source: SourceFile, start: Int, end: Int): Unit
}


Expand Down
36 changes: 0 additions & 36 deletions library/src/scala/quoted/report.scala

This file was deleted.

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 @@ -11,7 +11,7 @@ object BigFloatFromDigitsImpl:
val BigFloat(m, e) = BigFloat(ds)
'{BigFloat(${Expr(m)}, ${Expr(e)})}
catch case ex: FromDigits.FromDigitsException =>
report.error(ex.getMessage)
quotes.reflect.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 @@ -10,7 +10,7 @@ object EvenFromDigitsImpl:
try evenFromDigits(ds)
catch {
case ex: FromDigits.FromDigitsException =>
report.error(ex.getMessage)
quotes.reflect.report.error(ex.getMessage)
Even(0)
}
'{Even(${Expr(ev.n)})}
Expand Down
6 changes: 3 additions & 3 deletions tests/neg-macros/delegate-match-1/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ private def fImpl(using Quotes): Expr[Unit] = {
case x: ImplicitSearchSuccess =>
'{}
case x: DivergingImplicit => '{}
Reporting.error("DivergingImplicit\n" + x.explanation, Position.ofMacroExpansion)
report.error("DivergingImplicit\n" + x.explanation, Position.ofMacroExpansion)
'{}
case x: NoMatchingImplicits =>
Reporting.error("NoMatchingImplicits\n" + x.explanation, Position.ofMacroExpansion)
report.error("NoMatchingImplicits\n" + x.explanation, Position.ofMacroExpansion)
'{}
case x: AmbiguousImplicits =>
Reporting.error("AmbiguousImplicits\n" + x.explanation, Position.ofMacroExpansion)
report.error("AmbiguousImplicits\n" + x.explanation, Position.ofMacroExpansion)
'{}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/neg-macros/delegate-match-2/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ private def fImpl (using Quotes) : Expr[Unit] = {
case x: ImplicitSearchSuccess =>
'{}
case x: DivergingImplicit => '{}
Reporting.error("DivergingImplicit\n" + x.explanation, Position.ofMacroExpansion)
report.error("DivergingImplicit\n" + x.explanation, Position.ofMacroExpansion)
'{}
case x: NoMatchingImplicits =>
Reporting.error("NoMatchingImplicits\n" + x.explanation, Position.ofMacroExpansion)
report.error("NoMatchingImplicits\n" + x.explanation, Position.ofMacroExpansion)
'{}
case x: AmbiguousImplicits =>
Reporting.error("AmbiguousImplicits\n" + x.explanation, Position.ofMacroExpansion)
report.error("AmbiguousImplicits\n" + x.explanation, Position.ofMacroExpansion)
'{}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/neg-macros/delegate-match-3/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ private def fImpl(using Quotes) : Expr[Unit] = {
case x: ImplicitSearchSuccess =>
'{}
case x: DivergingImplicit => '{}
Reporting.error("DivergingImplicit\n" + x.explanation, Position.ofMacroExpansion)
report.error("DivergingImplicit\n" + x.explanation, Position.ofMacroExpansion)
'{}
case x: NoMatchingImplicits =>
Reporting.error("NoMatchingImplicits\n" + x.explanation, Position.ofMacroExpansion)
report.error("NoMatchingImplicits\n" + x.explanation, Position.ofMacroExpansion)
'{}
case x: AmbiguousImplicits =>
Reporting.error("AmbiguousImplicits\n" + x.explanation, Position.ofMacroExpansion)
report.error("AmbiguousImplicits\n" + x.explanation, Position.ofMacroExpansion)
'{}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i6432/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Macro {
sc match {
case '{ StringContext(${Varargs(parts)}: _*) } =>
for (part @ Const(s) <- parts)
Reporting.error(s, Term.of(part).pos)
report.error(s, Term.of(part).pos)
}
'{}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i6432b/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Macro {
sc match {
case '{ StringContext(${Varargs(parts)}: _*) } =>
for (part @ Const(s) <- parts)
Reporting.error(s, Term.of(part).pos)
report.error(s, Term.of(part).pos)
}
'{}
}
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 Bar = ${ impl }
def impl(using Quotes): Expr[Bar] = report.throwError("Failed to expand!")
def impl(using Quotes): Expr[Bar] = quotes.reflect.report.throwError("Failed to expand!")
2 changes: 1 addition & 1 deletion tests/neg-macros/i9801/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ def impl(prog: Expr[Double])(using Quotes) : Expr[Double] =
triggerStackOverflow(0)
} catch {
case e =>
quotes.reflect.Reporting.error(e.getMessage, Term.of(prog).pos)
quotes.reflect.report.error(e.getMessage, Term.of(prog).pos)
'{ 42.0 }
}
2 changes: 1 addition & 1 deletion tests/neg-macros/macros-in-same-project-6/Foo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Foo {

def aMacroImplementation(using Quotes) : Expr[Unit] = {
import quotes.reflect._
Reporting.error("some error", Position.ofMacroExpansion)
report.error("some error", Position.ofMacroExpansion)
throw new NoClassDefFoundError("Bar$")
}
}
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 Quotes): Expr[String] =
if (b) '{"foo(true)"}
else { report.error("foo cannot be called with false"); '{ ??? } }
else { quotes.reflect.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 Quotes) : Expr[Unit] =
if (b.unliftOrError) '{println("foo(true)")}
else { report.error("foo cannot be called with false"); '{ ??? } }
else { quotes.reflect.report.error("foo cannot be called with false"); '{ ??? } }
}
2 changes: 1 addition & 1 deletion tests/neg-macros/tasty-macro-error/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Macros {

def impl(x: Expr[Any])(using Quotes) : Expr[Unit] = {
import quotes.reflect._
Reporting.error("here is the the argument is " + Term.of(x).underlyingArgument.show, Term.of(x).underlyingArgument.pos)
report.error("here is the the argument is " + Term.of(x).underlyingArgument.show, Term.of(x).underlyingArgument.pos)
'{}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/neg-macros/tasty-macro-positions/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ object Macros {
def impl(x: Expr[Any])(using Quotes) : Expr[Unit] = {
import quotes.reflect._
val pos = Term.of(x).underlyingArgument.pos
Reporting.error("here is the the argument is " + Term.of(x).underlyingArgument.show, pos)
Reporting.error("here (+5) is the the argument is " + Term.of(x).underlyingArgument.show, pos.sourceFile, pos.start + 5, pos.end + 5)
report.error("here is the the argument is " + Term.of(x).underlyingArgument.show, pos)
report.error("here (+5) is the the argument is " + Term.of(x).underlyingArgument.show, pos.sourceFile, pos.start + 5, pos.end + 5)
'{}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object FIntepolator {

def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes) : Expr[String] = {
import quotes.reflect._
Reporting.error("there are no parts", Term.of(strCtxExpr).underlyingArgument.pos)
report.error("there are no parts", Term.of(strCtxExpr).underlyingArgument.pos)
'{ ($strCtxExpr).s($argsExpr: _*) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Macro {
object FIntepolator {
def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes) : Expr[String] = {
import quotes.reflect._
Reporting.error("there are no args", Term.of(argsExpr).underlyingArgument.pos)
report.error("there are no args", Term.of(argsExpr).underlyingArgument.pos)
'{ ($strCtxExpr).s($argsExpr: _*) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object EvenFromDigitsImpl:
try evenFromDigits(ds)
catch {
case ex: FromDigits.FromDigitsException =>
report.error(ex.getMessage)
quotes.reflect.report.error(ex.getMessage)
Even(0)
}
'{Even(${Expr(ev.n)})}
Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ object BigFloatFromDigitsImpl:
val BigFloat(m, e) = BigFloat(ds)
'{BigFloat(${Expr(m)}, ${Expr(e)})}
catch case ex: FromDigits.FromDigitsException =>
import quotes.reflect.report
report.error(ex.getMessage)
'{BigFloat(0, 0)}
case digits =>
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i8671/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object FileName {
Right(FileName.unsafe(s))

def createFileName(fileName: Expr[String])(using Quotes): Expr[FileName] =
import quotes.reflect.report
fileName match {
case e@Const(s) =>
fileNameFromString(s) match {
Expand All @@ -25,4 +26,3 @@ object 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-1/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object Macros {

case _ =>
import quotes.reflect._
Reporting.error("Expected explicit DSL", Term.of(e).pos)
report.error("Expected explicit DSL", Term.of(e).pos)
'{ ??? }

}
Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/quote-matcher-symantics-2/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object Macros {

case _ =>
import quotes.reflect._
Reporting.error("Expected explicit DSL " + e.show, Term.of(e).pos)
report.error("Expected explicit DSL " + e.show, Term.of(e).pos)
???
}

Expand All @@ -53,7 +53,7 @@ object Macros {
)
case _ =>
import quotes.reflect._
Reporting.error("Expected explicit DSL => DSL " + e.show, Term.of(e).pos)
report.error("Expected explicit DSL => DSL " + e.show, Term.of(e).pos)
???
}

Expand Down
Loading