Skip to content

Commit 62b8b8e

Browse files
Merge pull request #10474 from dotty-staging/unify-quoted-reporters
Unify quoted.report and reflect.Reporting
2 parents 1c3538a + 81991f6 commit 62b8b8e

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): Nothing =
2567+
error(msg, pos)
2568+
throw new scala.quoted.runtime.StopMacroExpansion
2569+
2570+
def throwError(msg: String, sourceFile: SourceFile, start: Int, end: Int): Nothing =
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): Nothing
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): Nothing
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
}

tests/neg-macros/delegate-match-3/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/i6432/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Macro {
1010
sc match {
1111
case '{ StringContext(${Varargs(parts)}: _*) } =>
1212
for (part @ Const(s) <- parts)
13-
Reporting.error(s, Term.of(part).pos)
13+
report.error(s, Term.of(part).pos)
1414
}
1515
'{}
1616
}

tests/neg-macros/i6432b/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Macro {
1010
sc match {
1111
case '{ StringContext(${Varargs(parts)}: _*) } =>
1212
for (part @ Const(s) <- parts)
13-
Reporting.error(s, Term.of(part).pos)
13+
report.error(s, Term.of(part).pos)
1414
}
1515
'{}
1616
}

tests/neg-macros/i9014/Macros_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import scala.quoted._
22
trait Bar
33
inline given Bar = ${ impl }
4-
def impl(using Quotes): Expr[Bar] = report.throwError("Failed to expand!")
4+
def impl(using Quotes): Expr[Bar] = quotes.reflect.report.throwError("Failed to expand!")

tests/neg-macros/i9801/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def impl(prog: Expr[Double])(using Quotes) : Expr[Double] =
1616
triggerStackOverflow(0)
1717
} catch {
1818
case e =>
19-
quotes.reflect.Reporting.error(e.getMessage, Term.of(prog).pos)
19+
quotes.reflect.report.error(e.getMessage, Term.of(prog).pos)
2020
'{ 42.0 }
2121
}

tests/neg-macros/macros-in-same-project-6/Foo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Foo {
66

77
def aMacroImplementation(using Quotes) : Expr[Unit] = {
88
import quotes.reflect._
9-
Reporting.error("some error", Position.ofMacroExpansion)
9+
report.error("some error", Position.ofMacroExpansion)
1010
throw new NoClassDefFoundError("Bar$")
1111
}
1212
}

tests/neg-macros/quote-error-2/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ object Macro_1 {
77

88
def msg(b: Boolean)(using Quotes): Expr[String] =
99
if (b) '{"foo(true)"}
10-
else { report.error("foo cannot be called with false"); '{ ??? } }
10+
else { quotes.reflect.report.error("foo cannot be called with false"); '{ ??? } }
1111

1212
}

tests/neg-macros/quote-error/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ object Macro_1 {
44
inline def foo(inline b: Boolean): Unit = ${fooImpl('b)}
55
def fooImpl(b: Expr[Boolean])(using Quotes) : Expr[Unit] =
66
if (b.unliftOrError) '{println("foo(true)")}
7-
else { report.error("foo cannot be called with false"); '{ ??? } }
7+
else { quotes.reflect.report.error("foo cannot be called with false"); '{ ??? } }
88
}

tests/neg-macros/tasty-macro-error/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Macros {
66

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

tests/neg-macros/tasty-macro-positions/quoted_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ object Macros {
77
def impl(x: Expr[Any])(using Quotes) : Expr[Unit] = {
88
import quotes.reflect._
99
val pos = Term.of(x).underlyingArgument.pos
10-
Reporting.error("here is the the argument is " + Term.of(x).underlyingArgument.show, pos)
11-
Reporting.error("here (+5) is the the argument is " + Term.of(x).underlyingArgument.show, pos.sourceFile, pos.start + 5, pos.end + 5)
10+
report.error("here is the the argument is " + Term.of(x).underlyingArgument.show, pos)
11+
report.error("here (+5) is the the argument is " + Term.of(x).underlyingArgument.show, pos.sourceFile, pos.start + 5, pos.end + 5)
1212
'{}
1313
}
1414

tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object FIntepolator {
1111

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

tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Macro {
1010
object FIntepolator {
1111
def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes) : Expr[String] = {
1212
import quotes.reflect._
13-
Reporting.error("there are no args", Term.of(argsExpr).underlyingArgument.pos)
13+
report.error("there are no args", Term.of(argsExpr).underlyingArgument.pos)
1414
'{ ($strCtxExpr).s($argsExpr: _*) }
1515
}
1616

tests/neg-with-compiler/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/run-macros/BigFloat/BigFloatFromDigitsImpl_1.scala

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

tests/run-macros/i8671/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ object FileName {
1212
Right(FileName.unsafe(s))
1313

1414
def createFileName(fileName: Expr[String])(using Quotes): Expr[FileName] =
15+
import quotes.reflect.report
1516
fileName match {
1617
case e@Const(s) =>
1718
fileNameFromString(s) match {
@@ -25,4 +26,3 @@ object FileName {
2526
report.throwError(s"$fileName is not a valid file name. It must be a literal string", fileName)
2627
}
2728
}
28-

tests/run-macros/quote-matcher-symantics-1/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object Macros {
2121

2222
case _ =>
2323
import quotes.reflect._
24-
Reporting.error("Expected explicit DSL", Term.of(e).pos)
24+
report.error("Expected explicit DSL", Term.of(e).pos)
2525
'{ ??? }
2626

2727
}

tests/run-macros/quote-matcher-symantics-2/quoted_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object Macros {
3939

4040
case _ =>
4141
import quotes.reflect._
42-
Reporting.error("Expected explicit DSL " + e.show, Term.of(e).pos)
42+
report.error("Expected explicit DSL " + e.show, Term.of(e).pos)
4343
???
4444
}
4545

@@ -53,7 +53,7 @@ object Macros {
5353
)
5454
case _ =>
5555
import quotes.reflect._
56-
Reporting.error("Expected explicit DSL => DSL " + e.show, Term.of(e).pos)
56+
report.error("Expected explicit DSL => DSL " + e.show, Term.of(e).pos)
5757
???
5858
}
5959

0 commit comments

Comments
 (0)