Skip to content

Commit 22ba037

Browse files
committed
Unify quoted.report and reflect.Reporting
Make a single `reflect.report` that contains all reporting functionality. Also, make message parameters by-value.
1 parent 6a56706 commit 22ba037

File tree

32 files changed

+111
-91
lines changed

32 files changed

+111
-91
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,19 +2541,49 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
25412541
def path: java.nio.file.Path = ctx.compilationUnit.source.file.jpath
25422542
end Source
25432543

2544-
object Reporting extends ReportingModule:
2545-
def error(msg: => String, pos: Position): Unit =
2544+
object report extends ReportModule:
2545+
2546+
def error(msg: String): Unit =
2547+
dotc.report.error(msg, Position.ofMacroExpansion)
2548+
2549+
def error(msg: String, expr: Expr[Any]): Unit =
2550+
dotc.report.error(msg, Term.of(expr).pos)
2551+
2552+
def error(msg: String, pos: Position): Unit =
25462553
dotc.report.error(msg, pos)
25472554

2548-
def error(msg: => String, sourceFile: SourceFile, start: Int, end: Int): Unit =
2555+
def error(msg: String, sourceFile: SourceFile, start: Int, end: Int): Unit =
25492556
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))
25502557

2551-
def warning(msg: => String, pos: Position): Unit =
2558+
def throwError(msg: String): Nothing =
2559+
error(msg)
2560+
throw new scala.quoted.runtime.StopMacroExpansion
2561+
2562+
def throwError(msg: String, expr: Expr[Any]): Nothing =
2563+
error(msg, expr)
2564+
throw new scala.quoted.runtime.StopMacroExpansion
2565+
2566+
def throwError(msg: String, pos: Position): Unit =
2567+
error(msg, pos)
2568+
throw new scala.quoted.runtime.StopMacroExpansion
2569+
2570+
def throwError(msg: String, sourceFile: SourceFile, start: Int, end: Int): Unit =
2571+
error(msg, sourceFile, start, end)
2572+
throw new scala.quoted.runtime.StopMacroExpansion
2573+
2574+
def warning(msg: String): Unit =
2575+
dotc.report.warning(msg, Position.ofMacroExpansion)
2576+
2577+
def warning(msg: String, expr: Expr[Any]): Unit =
2578+
dotc.report.warning(msg, Term.of(expr).pos)
2579+
2580+
def warning(msg: String, pos: Position): Unit =
25522581
dotc.report.warning(msg, pos)
25532582

2554-
def warning(msg: => String, sourceFile: SourceFile, start: Int, end: Int): Unit =
2583+
def warning(msg: String, sourceFile: SourceFile, start: Int, end: Int): Unit =
25552584
dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end)))
2556-
end Reporting
2585+
2586+
end report
25572587

25582588
type Documentation = dotc.core.Comments.Comment
25592589

library/src/scala/quoted/Quotes.scala

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
4949
def unliftOrError(using Unliftable[T]): T =
5050
def reportError =
5151
val msg = s"Expected a known value. \n\nThe value of: ${self.show}\ncould not be unlifted using $unlift"
52-
report.throwError(msg, self)(using Quotes.this)
52+
reflect.report.throwError(msg, self)
5353
summon[Unliftable[T]].fromExpr(self)(using Quotes.this).getOrElse(reportError)
5454

5555
end extension
@@ -3381,24 +3381,47 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
33813381
// REPORTING //
33823382
///////////////
33833383

3384-
val Reporting: ReportingModule
3384+
val report: ReportModule
33853385

3386-
/** Module containg error and waring reporiting.
3387-
*
3388-
* Also see scala.quoted.report
3389-
*/
3390-
trait ReportingModule { self: Reporting.type =>
3391-
/** Emits an error message */
3392-
def error(msg: => String, pos: Position): Unit
3386+
/** Module containg error and waring reporiting. */
3387+
trait ReportModule { self: report.type =>
3388+
3389+
/** Report an error at the position of the macro expansion */
3390+
def error(msg: String): Unit
3391+
3392+
/** Report an error at the position of `expr` */
3393+
def error(msg: String, expr: Expr[Any]): Unit
3394+
3395+
/** Report an error message at the given position */
3396+
def error(msg: String, pos: Position): Unit
3397+
3398+
/** Report an error at a specific range of a file. The positions must be contained in the file. */
3399+
def error(msg: String, source: SourceFile, start: Int, end: Int): Unit
3400+
3401+
/** Report an error at the position of the macro expansion and throws a StopMacroExpansion */
3402+
def throwError(msg: String): Nothing
3403+
3404+
/** Report an error at the position of `expr` */
3405+
def throwError(msg: String, expr: Expr[Any]): Nothing
3406+
3407+
/** Report an error message at the given position and throws a StopMacroExpansion */
3408+
def throwError(msg: String, pos: Position): Unit
3409+
3410+
/** Report an error at a specific range of a file and throws a StopMacroExpansion. The positions must be contained in the file. */
3411+
def throwError(msg: String, source: SourceFile, start: Int, end: Int): Unit
3412+
3413+
/** Report a warning at the position of the macro expansion */
3414+
def warning(msg: String): Unit
3415+
3416+
/** Report a warning at the on the position of `expr` */
3417+
def warning(msg: String, expr: Expr[Any]): Unit
33933418

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

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

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

34043427

library/src/scala/quoted/report.scala

Lines changed: 0 additions & 36 deletions
This file was deleted.

tests/neg-macros/BigFloat/BigFloatFromDigitsImpl_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object BigFloatFromDigitsImpl:
1111
val BigFloat(m, e) = BigFloat(ds)
1212
'{BigFloat(${Expr(m)}, ${Expr(e)})}
1313
catch case ex: FromDigits.FromDigitsException =>
14-
report.error(ex.getMessage)
14+
quotes.reflect.report.error(ex.getMessage)
1515
'{BigFloat(0, 0)}
1616
case digits =>
1717
'{BigFloat($digits)}

tests/neg-macros/GenericNumLits/EvenFromDigitsImpl_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object EvenFromDigitsImpl:
1010
try evenFromDigits(ds)
1111
catch {
1212
case ex: FromDigits.FromDigitsException =>
13-
report.error(ex.getMessage)
13+
quotes.reflect.report.error(ex.getMessage)
1414
Even(0)
1515
}
1616
'{Even(${Expr(ev.n)})}

tests/neg-macros/delegate-match-1/Macro_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ private def fImpl(using Quotes): Expr[Unit] = {
99
case x: ImplicitSearchSuccess =>
1010
'{}
1111
case x: DivergingImplicit => '{}
12-
Reporting.error("DivergingImplicit\n" + x.explanation, Position.ofMacroExpansion)
12+
report.error("DivergingImplicit\n" + x.explanation, Position.ofMacroExpansion)
1313
'{}
1414
case x: NoMatchingImplicits =>
15-
Reporting.error("NoMatchingImplicits\n" + x.explanation, Position.ofMacroExpansion)
15+
report.error("NoMatchingImplicits\n" + x.explanation, Position.ofMacroExpansion)
1616
'{}
1717
case x: AmbiguousImplicits =>
18-
Reporting.error("AmbiguousImplicits\n" + x.explanation, Position.ofMacroExpansion)
18+
report.error("AmbiguousImplicits\n" + x.explanation, Position.ofMacroExpansion)
1919
'{}
2020
}
2121
}

tests/neg-macros/delegate-match-2/Macro_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ private def fImpl (using Quotes) : Expr[Unit] = {
99
case x: ImplicitSearchSuccess =>
1010
'{}
1111
case x: DivergingImplicit => '{}
12-
Reporting.error("DivergingImplicit\n" + x.explanation, Position.ofMacroExpansion)
12+
report.error("DivergingImplicit\n" + x.explanation, Position.ofMacroExpansion)
1313
'{}
1414
case x: NoMatchingImplicits =>
15-
Reporting.error("NoMatchingImplicits\n" + x.explanation, Position.ofMacroExpansion)
15+
report.error("NoMatchingImplicits\n" + x.explanation, Position.ofMacroExpansion)
1616
'{}
1717
case x: AmbiguousImplicits =>
18-
Reporting.error("AmbiguousImplicits\n" + x.explanation, Position.ofMacroExpansion)
18+
report.error("AmbiguousImplicits\n" + x.explanation, Position.ofMacroExpansion)
1919
'{}
2020
}
2121
}

0 commit comments

Comments
 (0)