@@ -42,13 +42,15 @@ object PickledQuotes {
4242 def quotedExprToTree [T ](expr : quoted.Expr [T ])(using Context ): Tree = {
4343 val expr1 = expr.asInstanceOf [ExprImpl ]
4444 expr1.checkScopeId(QuotesImpl .scopeId)
45+ ScopeException .checkInCorrectScope(expr1.scope, SpliceScope .getCurrent, expr1.tree, " Expr" )
4546 changeOwnerOfTree(expr1.tree, ctx.owner)
4647 }
4748
4849 /** Transform the expression into its fully spliced TypeTree */
4950 def quotedTypeToTree (tpe : quoted.Type [? ])(using Context ): Tree = {
5051 val tpe1 = tpe.asInstanceOf [TypeImpl ]
5152 tpe1.checkScopeId(QuotesImpl .scopeId)
53+ ScopeException .checkInCorrectScope(tpe1.scope, SpliceScope .getCurrent, tpe1.typeTree, " Type" )
5254 changeOwnerOfTree(tpe1.typeTree, ctx.owner)
5355 }
5456
@@ -73,23 +75,25 @@ object PickledQuotes {
7375 val evaluateHoles = new TreeMap {
7476 override def transform (tree : tpd.Tree )(using Context ): tpd.Tree = tree match {
7577 case Hole (isTerm, idx, args) =>
76- val reifiedArgs = args.map { arg =>
77- if (arg.isTerm) (q : Quotes ) ?=> new ExprImpl (arg, QuotesImpl .scopeId)
78- else new TypeImpl (arg, QuotesImpl .scopeId)
78+ inContext(SpliceScope .contextWithNewSpliceScope(tree.sourcePos)) {
79+ val reifiedArgs = args.map { arg =>
80+ if (arg.isTerm) (q : Quotes ) ?=> new ExprImpl (arg, QuotesImpl .scopeId, SpliceScope .getCurrent)
81+ else new TypeImpl (arg, QuotesImpl .scopeId, SpliceScope .getCurrent)
82+ }
83+ if isTerm then
84+ val quotedExpr = termHole(idx, reifiedArgs, QuotesImpl ())
85+ val filled = PickledQuotes .quotedExprToTree(quotedExpr)
86+
87+ // We need to make sure a hole is created with the source file of the surrounding context, even if
88+ // it filled with contents a different source file.
89+ if filled.source == ctx.source then filled
90+ else filled.cloneIn(ctx.source).withSpan(tree.span)
91+ else
92+ // Replaces type holes generated by PickleQuotes (non-spliced types).
93+ // These are types defined in a quote and used at the same level in a nested quote.
94+ val quotedType = typeHole(idx, reifiedArgs)
95+ PickledQuotes .quotedTypeToTree(quotedType)
7996 }
80- if isTerm then
81- val quotedExpr = termHole(idx, reifiedArgs, QuotesImpl ())
82- val filled = PickledQuotes .quotedExprToTree(quotedExpr)
83-
84- // We need to make sure a hole is created with the source file of the surrounding context, even if
85- // it filled with contents a different source file.
86- if filled.source == ctx.source then filled
87- else filled.cloneIn(ctx.source).withSpan(tree.span)
88- else
89- // Replaces type holes generated by PickleQuotes (non-spliced types).
90- // These are types defined in a quote and used at the same level in a nested quote.
91- val quotedType = typeHole(idx, reifiedArgs)
92- PickledQuotes .quotedTypeToTree(quotedType)
9397 case tree : Select =>
9498 // Retain selected members
9599 val qual = transform(tree.qualifier)
0 commit comments