Skip to content

Commit ddfc83d

Browse files
EugeneFlesselleWojciechMazur
authored andcommitted
Map over ImportTypes 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 [Cherry-picked 413d7b4]
1 parent 6e76dbe commit ddfc83d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

+5
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,11 @@ class Inliner(val call: tpd.Tree)(using Context):
565565
def apply(t: Type) = t match {
566566
case t: ThisType => thisProxy.getOrElse(t.cls, t)
567567
case t: TypeRef => paramProxy.getOrElse(t, mapOver(t))
568+
case t: TermRef if t.symbol.isImport =>
569+
val ImportType(e) = t.widenTermRefExpr: @unchecked
570+
paramProxy.get(e.tpe) match
571+
case Some(p) => newImportSymbol(ctx.owner, singleton(p)).termRef
572+
case None => mapOver(t)
568573
case t: SingletonType =>
569574
if t.termSymbol.isAllOf(InlineParam) then apply(t.widenTermRefExpr)
570575
else paramProxy.getOrElse(t, mapOver(t))

tests/pos/i19493.scala

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
import scala.compiletime.{summonAll, summonInline}
3+
import deriving.Mirror
4+
5+
type Sc[X] = X
6+
case class Row[T[_]](name: T[String])
7+
8+
class DialectTypeMappers:
9+
given String = ???
10+
11+
inline def metadata(dialect: DialectTypeMappers)(using m: Mirror.Of[Row[Sc]]): m.MirroredElemTypes =
12+
import dialect.given
13+
summonAll[m.MirroredElemTypes]
14+
15+
def f = metadata(???)
16+
17+
18+
object Minimization:
19+
20+
class GivesString:
21+
given aString: String = ???
22+
23+
inline def foo(x: GivesString): Unit =
24+
import x.aString
25+
summon[String]
26+
summonInline[String] // was error
27+
28+
foo(???)
29+
end Minimization

0 commit comments

Comments
 (0)