Skip to content

Commit

Permalink
Map over ImportTypes in inliner tree type map
Browse files Browse the repository at this point in the history
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
  • Loading branch information
EugeneFlesselle committed Jun 27, 2024
1 parent 41f1489 commit d9d7f28
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
29 changes: 29 additions & 0 deletions tests/pos/i19493.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d9d7f28

Please sign in to comment.