11package dotty .tools .dotc .tastyreflect
22
3- import dotty .tools .dotc .core .Contexts .FreshContext
43import dotty .tools .dotc .core .quoted .PickledQuotes
5- import dotty .tools .dotc .reporting .Reporter
6- import dotty .tools .dotc .reporting .diagnostic .MessageContainer
74
85trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with CoreImpl {
96
@@ -18,30 +15,17 @@ trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with CoreImpl {
1815 def TermToQuoteDeco (term : Term ): TermToQuotedAPI = new TermToQuotedAPI {
1916
2017 def seal [T : scala.quoted.Type ](implicit ctx : Context ): scala.quoted.Expr [T ] = {
21- typecheck(ctx )
18+ typecheck()
2219 new scala.quoted.Exprs .TastyTreeExpr (term).asInstanceOf [scala.quoted.Expr [T ]]
2320 }
2421
25- private def typecheck [T : scala.quoted.Type ](ctx : Context ): Unit = {
26- implicit val ctx0 : FreshContext = ctx.fresh
27- ctx0.setTyperState(ctx0.typerState.fresh())
28- ctx0.typerState.setReporter(new Reporter {
29- def doReport (m : MessageContainer )(implicit ctx : Context ): Unit = ()
30- })
31- val tp = QuotedTypeDeco (implicitly[scala.quoted.Type [T ]]).unseal
32- ctx0.typer.typed(term, tp.tpe)
33- if (ctx0.reporter.hasErrors) {
34- val stack = new Exception ().getStackTrace
35- def filter (elem : StackTraceElement ) =
36- elem.getClassName.startsWith(" dotty.tools.dotc.tasty.ReflectionImpl" ) ||
37- ! elem.getClassName.startsWith(" dotty.tools.dotc" )
22+ private def typecheck [T : scala.quoted.Type ]()(implicit ctx : Context ): Unit = {
23+ val tpt = QuotedTypeDeco (implicitly[scala.quoted.Type [T ]]).unseal
24+ if (! (term.tpe <:< tpt.tpe)) {
3825 throw new scala.tasty.TastyTypecheckError (
39- s """ Error during tasty reflection while typing term
40- |term: ${term.show}
41- |with expected type: ${tp.tpe.show}
42- |
43- | ${stack.takeWhile(filter).mkString(" \n " )}
44- """ .stripMargin
26+ s """ Term: ${term.show}
27+ |did not conform to type: ${tpt.tpe.show}
28+ | """ .stripMargin
4529 )
4630 }
4731 }
0 commit comments