diff --git a/compiler/src/dotty/tools/dotc/staging/HealType.scala b/compiler/src/dotty/tools/dotc/staging/HealType.scala index a73f884fbac9..509049e131c8 100644 --- a/compiler/src/dotty/tools/dotc/staging/HealType.scala +++ b/compiler/src/dotty/tools/dotc/staging/HealType.scala @@ -76,7 +76,7 @@ class HealType(pos: SrcPos)(using Context) extends TypeMap { tp match case tp @ NamedType(NoPrefix, _) if level > levelOf(tp.symbol) => tp.symbol case tp: NamedType if !tp.symbol.isStatic => levelInconsistentRootOfPath(tp.prefix) - case tp: ThisType if level > levelOf(tp.cls) => tp.cls + case tp: ThisType if level > levelOf(tp.cls) && !tp.cls.isRefinementClass => tp.cls case _ => NoSymbol /** Try to heal reference to type `T` used in a higher level than its definition. diff --git a/tests/pos/i22648.scala b/tests/pos/i22648.scala new file mode 100644 index 000000000000..e1c7f73bb15e --- /dev/null +++ b/tests/pos/i22648.scala @@ -0,0 +1,14 @@ +import scala.quoted.* + +def fooImpl(using Quotes): Expr[Any] = + '{ + new AnyRef { + type T = Unit + def make: T = () + def take(t: T): Unit = () + }: { + type T + def make: T + def take(t: T): Unit + } + }