Skip to content

Commit 83b565a

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 ce65296 commit 83b565a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,15 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
241241
* reference to a type alias containing the equivalent of `${summon[quoted.Type[T]]}`.
242242
* Emits and error if `T` cannot be healed and returns `T`.
243243
*/
244-
protected def tryHeal(sym: Symbol, tp: TypeRef, pos: SrcPos)(using Context): TypeRef = {
244+
protected def tryHeal(sym: Symbol, tp: TypeRef, pos: SrcPos)(using Context): Type = {
245245
val reqType = defn.QuotedTypeClass.typeRef.appliedTo(tp)
246246
val tag = ctx.typer.inferImplicitArg(reqType, pos.span)
247247
tag.tpe match
248248

249249
case tp: TermRef =>
250250
checkStable(tp, pos, "type witness")
251-
getQuoteTypeTags.getTagRef(tp)
251+
if levelOf(tp.symbol) > 0 then tp.select(tpnme.Underlying)
252+
else getQuoteTypeTags.getTagRef(tp)
252253
case _: SearchFailureType =>
253254
report.error(
254255
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)