diff --git a/compiler/src/dotty/tools/dotc/staging/HealType.scala b/compiler/src/dotty/tools/dotc/staging/HealType.scala index 8b77f0774cdc..08e1e91b0bad 100644 --- a/compiler/src/dotty/tools/dotc/staging/HealType.scala +++ b/compiler/src/dotty/tools/dotc/staging/HealType.scala @@ -47,7 +47,10 @@ class HealType(pos: SrcPos)(using Context) extends TypeMap { checkNotWildcardSplice(tp) if level == 0 then tp else getTagRef(prefix) case _: TermRef | _: ThisType | NoPrefix => - if levelInconsistentRootOfPath(tp).exists then + val inconsistentRoot = levelInconsistentRootOfPath(tp) + if inconsistentRoot.isClass && inconsistentRoot.isLocal then + levelError(inconsistentRoot, tp, pos) + else if inconsistentRoot.exists then tryHeal(tp) else tp diff --git a/tests/neg-macros/i19856.scala b/tests/neg-macros/i19856.scala new file mode 100644 index 000000000000..990ae31d8db8 --- /dev/null +++ b/tests/neg-macros/i19856.scala @@ -0,0 +1,9 @@ +import scala.quoted.* + +def test(using Quotes): Any = + class Foo { + class IdxWrapper + def foo(using Type[IdxWrapper]): Expr[Any] = + '{ new IdxWrapper } // error + } + () diff --git a/tests/neg-macros/i19856b.scala b/tests/neg-macros/i19856b.scala new file mode 100644 index 000000000000..814b230a7ad0 --- /dev/null +++ b/tests/neg-macros/i19856b.scala @@ -0,0 +1,34 @@ +import scala.deriving.Mirror +import scala.quoted.{Expr, Quotes, Type} + +trait macroTest[A] { + type ElemTop <: A + type Index[_] + + case class IdxWrapper[X](idx: Index[X]) + + def indexOf[X <: ElemTop: Type](x: Expr[X]): Expr[Index[X]] + + def indexOfA(a: Expr[A]): Expr[IdxWrapper[_ <: ElemTop]] +} +object macroTest { + + def derivedImpl[A: Type, ElemTypes <: Tuple: Type, Label <: String: Type, Labels <: Tuple: Type]( + using m: Expr[ + Mirror.SumOf[A] { + type MirroredElemTypes = ElemTypes + type MirroredLabel = Label + type MirroredElemLabels = Labels + } + ], + q: Quotes, + ): macroTest[A] = new macroTest[A]: + override type Index[_] = Int + + override def indexOf[X <: ElemTop: Type](x: Expr[X]): Expr[Index[X]] = '{ $m.ordinal($x) } + + override def indexOfA(a: Expr[A]): Expr[IdxWrapper[_ <: ElemTop]] = + given Type[IdxWrapper] = Type.of[IdxWrapper] // error + given Type[ElemTop] = Type.of[ElemTop] // error + '{ new IdxWrapper(${ indexOf(a.asInstanceOf[Expr[ElemTop]]) }) } // error // error +}