From 1bb7fe07c83cb8958a6c9f6d2f15ccdee3022248 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Tue, 11 Mar 2025 13:23:37 +0100 Subject: [PATCH] Skip splice level checking for symbols This is safe to skip because symbols can only be a part of type refinement (where they reference that type), where it is impossible to splice anything. [Cherry-picked e989217a26916e58d2975c54f9a703235184e01a] --- .../src/dotty/tools/dotc/staging/HealType.scala | 2 +- tests/pos/i22648.scala | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i22648.scala 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 + } + }