File tree Expand file tree Collapse file tree 5 files changed +38
-0
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 5 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -635,6 +635,10 @@ class Definitions {
635
635
lazy val QuotedType_applyR = QuotedTypeModule .requiredMethodRef(nme.apply)
636
636
def QuotedType_apply (implicit ctx : Context ) = QuotedType_applyR .symbol
637
637
638
+ lazy val QuotedReporterModule = ctx.requiredModule(" scala.quoted.Reporter" )
639
+ lazy val QuotedReporterDummyR = QuotedReporterModule .requiredMethod(" dummy" .toTermName)
640
+ def QuotedReporterDummy (implicit ctx : Context ) = QuotedReporterDummyR .symbol
641
+
638
642
def Unpickler_unpickleExpr = ctx.requiredMethod(" scala.runtime.quoted.Unpickler.unpickleExpr" )
639
643
def Unpickler_unpickleType = ctx.requiredMethod(" scala.runtime.quoted.Unpickler.unpickleType" )
640
644
Original file line number Diff line number Diff line change @@ -72,6 +72,12 @@ class Interpreter(implicit ctx: Context) {
72
72
if (quotedTree.isTerm) new scala.quoted.Exprs .TreeExpr (quotedTree)
73
73
else new scala.quoted.Types .TreeType (quotedTree)
74
74
75
+ case tree : RefTree if tree.symbol eq defn.QuotedReporterDummy =>
76
+ new scala.quoted.Reporter {
77
+ override def error (message : String ): Unit = ctx.error(message, pos)
78
+ override def warn (message : String ): Unit = ctx.warning(message, pos)
79
+ }
80
+
75
81
case Literal (Constant (c)) => c.asInstanceOf [Object ]
76
82
77
83
case Apply (fn, args) if fn.symbol.isConstructor =>
Original file line number Diff line number Diff line change
1
+ package scala .quoted
2
+
3
+ trait Reporter {
4
+ def error (message : String ): Unit
5
+ def warn (message : String ): Unit
6
+ }
7
+
8
+ object Reporter {
9
+ object DummyReporter extends Reporter {
10
+ override def error (message : String ): Unit = ()
11
+ override def warn (message : String ): Unit = ()
12
+ }
13
+ implicit def dummy : Reporter = DummyReporter
14
+ }
Original file line number Diff line number Diff line change
1
+ import quoted ._
2
+
3
+ object Macro_1 {
4
+ inline def foo (inline b : Boolean ): Unit = ~ fooImpl(b)
5
+ def fooImpl (b : Boolean )(implicit reporter : Reporter ): Expr [Unit ] =
6
+ if (b) '(println("foo(true)"))
7
+ else reporter.error(" foo cannot be called with false" )
8
+ }
Original file line number Diff line number Diff line change
1
+ import Macro_1 ._
2
+
3
+ object Test_2 {
4
+ foo(true )
5
+ foo(false ) // error: foo cannot be called with false
6
+ }
You can’t perform that action at this time.
0 commit comments