Skip to content

Commit 06b5684

Browse files
committed
Avoid creation of @SplicedType quote local refrences
The type declarations annotated with `@SplicedType` are only meant for types that come from outside the quote. If the reference to the `Type[T]` is to a definition within the quote (i.e. its level is grater than 0) we can use it directly. The `@SplicedType` for that type will be generated in a future compilation phase when the `Type[T]` definition reaches level 0. Fixes #17026
1 parent f1bc0fb commit 06b5684

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

compiler/src/dotty/tools/dotc/staging/HealType.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package staging
44
import dotty.tools.dotc.core.Contexts._
55
import dotty.tools.dotc.core.Decorators._
66
import dotty.tools.dotc.core.Flags._
7+
import dotty.tools.dotc.core.StdNames._
78
import dotty.tools.dotc.core.Symbols._
89
import dotty.tools.dotc.core.Types._
910
import dotty.tools.dotc.staging.QuoteContext.*
@@ -68,13 +69,14 @@ class HealType(pos: SrcPos)(using Context) extends TypeMap {
6869
* reference to a type alias containing the equivalent of `${summon[quoted.Type[T]]}`.
6970
* Emits an error if `T` cannot be healed and returns `T`.
7071
*/
71-
protected def tryHeal(sym: Symbol, tp: TypeRef, pos: SrcPos): TypeRef = {
72+
protected def tryHeal(sym: Symbol, tp: TypeRef, pos: SrcPos): Type = {
7273
val reqType = defn.QuotedTypeClass.typeRef.appliedTo(tp)
7374
val tag = ctx.typer.inferImplicitArg(reqType, pos.span)
7475
tag.tpe match
7576
case tp: TermRef =>
7677
ctx.typer.checkStable(tp, pos, "type witness")
77-
getQuoteTypeTags.getTagRef(tp)
78+
if levelOf(tp.symbol) > 0 then tp.select(tpnme.Underlying)
79+
else getQuoteTypeTags.getTagRef(tp)
7880
case _: SearchFailureType =>
7981
report.error(
8082
ctx.typer.missingArgMsg(tag, reqType, "")

tests/pos-macros/i17026.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import scala.quoted.*
2+
def macroImpl(using Quotes) =
3+
'{ def weird[A: Type](using Quotes) = Type.of[A] }

tests/pos-macros/i17026b.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted.*
2+
3+
def macroImpl(using Quotes) =
4+
'{
5+
def weird[A: ToExpr: Type](a: A)(using quotes: Quotes) =
6+
'{ Some(${ Expr(a) }) }
7+
}

0 commit comments

Comments
 (0)