diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 4909602915d3..78fe3984efa5 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -125,6 +125,12 @@ object TypeOps: } def isLegalPrefix(pre: Type)(using Context): Boolean = + // This used to be `pre.isStable || !ctx.phase.isTyper` but the latter + // condition was dropped in #21954 to make implicit search during the + // inlining phase behave more like implicit search during the typer phase. + // However, this change has led to retyping issues (#23423) and I suspect + // other issues could crop up as we might end up calling asSeenFrom with a + // widened prefix in various situations post-typer. pre.isStable /** Implementation of Types#simplified */ diff --git a/compiler/src/dotty/tools/dotc/staging/HealType.scala b/compiler/src/dotty/tools/dotc/staging/HealType.scala index 509049e131c8..37e77f3e7386 100644 --- a/compiler/src/dotty/tools/dotc/staging/HealType.scala +++ b/compiler/src/dotty/tools/dotc/staging/HealType.scala @@ -32,12 +32,14 @@ class HealType(pos: SrcPos)(using Context) extends TypeMap { */ def apply(tp: Type): Type = tp match - case NonSpliceAlias(aliased) => this.apply(aliased) - case tp: TypeRef => healTypeRef(tp) - case tp: TermRef => - val inconsistentRoot = levelInconsistentRootOfPath(tp) - if inconsistentRoot.exists then levelError(inconsistentRoot, tp, pos) - else mapOver(tp) + case tp: NamedType if tp.symbol.isLocal => tp match + case NonSpliceAlias(aliased) => + this.apply(aliased) + case tp: TypeRef => healTypeRef(tp) + case tp: TermRef => + val inconsistentRoot = levelInconsistentRootOfPath(tp) + if inconsistentRoot.exists then levelError(inconsistentRoot, tp, pos) + else mapOver(tp) case tp: AnnotatedType => derivedAnnotatedType(tp, apply(tp.parent), tp.annot) case _ => diff --git a/tests/pos-macros/i23423/A_1.scala b/tests/pos-macros/i23423/A_1.scala new file mode 100644 index 000000000000..62455c74eed0 --- /dev/null +++ b/tests/pos-macros/i23423/A_1.scala @@ -0,0 +1,16 @@ +package pkg + +import scala.quoted.* + +trait HasElem { + type Elem + type Alias = Elem +} + +object Macro: + inline def foo: Unit = ${fooImpl} + def fooImpl(using Quotes): Expr[Unit] = + '{ + val lll: (he: HasElem) => he.Alias = + (hx: HasElem) => ??? + } diff --git a/tests/pos-macros/i23423/B_2.scala b/tests/pos-macros/i23423/B_2.scala new file mode 100644 index 000000000000..144eaf4ce1da --- /dev/null +++ b/tests/pos-macros/i23423/B_2.scala @@ -0,0 +1,6 @@ +object Test: + def test: Unit = pkg.Macro.foo + // used to be error: + // Found: (hx: pkg.HasElem) => hx.Elem + // Required: (he: pkg.HasElem) => he.Elem +