From 581ad05a65a57bf4e77b63b60c17cc72eb180cbe Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Wed, 27 Mar 2024 15:20:21 +0100 Subject: [PATCH] Map over `ImportType`s in inliner tree type map The inliner replaces references to parameters by their corresponding proxys, including in singleton types. It did not, however, handle the mapping over import types, the symbols of which way have depended on parameters. Mapping imports correctly was necessary for i19493 since the `summonInline` resolves post inlining to a given imported within the inline definition. Fix #19493 --- .../dotty/tools/dotc/inlines/Inliner.scala | 5 ++++ tests/pos/i19493.scala | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/pos/i19493.scala diff --git a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala index 7c79e972c126..6116c00aeff7 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala @@ -565,6 +565,11 @@ class Inliner(val call: tpd.Tree)(using Context): def apply(t: Type) = t match { case t: ThisType => thisProxy.getOrElse(t.cls, t) case t: TypeRef => paramProxy.getOrElse(t, mapOver(t)) + case t: TermRef if t.symbol.isImport => + val ImportType(e) = t.widenTermRefExpr: @unchecked + paramProxy.get(e.tpe) match + case Some(p) => newImportSymbol(ctx.owner, singleton(p)).termRef + case None => mapOver(t) case t: SingletonType => if t.termSymbol.isAllOf(InlineParam) then apply(t.widenTermRefExpr) else paramProxy.getOrElse(t, mapOver(t)) diff --git a/tests/pos/i19493.scala b/tests/pos/i19493.scala new file mode 100644 index 000000000000..37af3214ce16 --- /dev/null +++ b/tests/pos/i19493.scala @@ -0,0 +1,29 @@ + +import scala.compiletime.{summonAll, summonInline} +import deriving.Mirror + +type Sc[X] = X +case class Row[T[_]](name: T[String]) + +class DialectTypeMappers: + given String = ??? + +inline def metadata(dialect: DialectTypeMappers)(using m: Mirror.Of[Row[Sc]]): m.MirroredElemTypes = + import dialect.given + summonAll[m.MirroredElemTypes] + +def f = metadata(???) + + +object Minimization: + + class GivesString: + given aString: String = ??? + + inline def foo(x: GivesString): Unit = + import x.aString + summon[String] + summonInline[String] // was error + + foo(???) +end Minimization