From e1233d80c5a870ebb51c72e4b26a8fc8004b3774 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 18 Jul 2023 14:32:36 +0200 Subject: [PATCH] Heal stage inconsistent prefixes of type projections Fixes #17293 --- compiler/src/dotty/tools/dotc/staging/HealType.scala | 2 +- tests/pos-macros/i17293.scala | 12 ++++++++++++ tests/pos-macros/i17293b.scala | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/pos-macros/i17293.scala create mode 100644 tests/pos-macros/i17293b.scala diff --git a/compiler/src/dotty/tools/dotc/staging/HealType.scala b/compiler/src/dotty/tools/dotc/staging/HealType.scala index 023271960b40..7d3ca0ad2f63 100644 --- a/compiler/src/dotty/tools/dotc/staging/HealType.scala +++ b/compiler/src/dotty/tools/dotc/staging/HealType.scala @@ -46,7 +46,7 @@ class HealType(pos: SrcPos)(using Context) extends TypeMap { case prefix: TermRef if tp.symbol.isTypeSplice => checkNotWildcardSplice(tp) if level == 0 then tp else getTagRef(prefix) - case _: NamedType | _: ThisType | NoPrefix => + case _: TermRef | _: ThisType | NoPrefix => if levelInconsistentRootOfPath(tp).exists then tryHeal(tp) else diff --git a/tests/pos-macros/i17293.scala b/tests/pos-macros/i17293.scala new file mode 100644 index 000000000000..57eba1181903 --- /dev/null +++ b/tests/pos-macros/i17293.scala @@ -0,0 +1,12 @@ +import scala.quoted.* + +trait OuterTrait { + trait X +} + +def exampleMacro[T <: OuterTrait: Type](expr: Expr[T])(using Quotes): Expr[OuterTrait#X] = { + '{ + val prefix: T = ${ expr } + new prefix.X {} + } +} diff --git a/tests/pos-macros/i17293b.scala b/tests/pos-macros/i17293b.scala new file mode 100644 index 000000000000..a8b73ba6176b --- /dev/null +++ b/tests/pos-macros/i17293b.scala @@ -0,0 +1,12 @@ +import scala.quoted.* + +trait OuterTrait { self => + trait X + + def exampleMacro[T <: self.type: Type](expr: Expr[T])(using Quotes): Expr[self.X] = { + '{ + val prefix: T = ${ expr } + new prefix.X {} + } + } +} \ No newline at end of file