Skip to content

Commit e8099d7

Browse files
authored
Merge pull request #12398 from dotty-staging/fix-12379
Fix #12379: Handle singleton types properly in proxy registeration
2 parents 62f202b + a46ec71 commit e8099d7

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
657657
paramBinding.get(tpe.name) match
658658
case Some(bound) => paramProxy(tpe) = bound
659659
case _ => // can happen for params bound by type-lambda trees.
660+
661+
// The widened type may contain param types too (see tests/pos/i12379a.scala)
662+
if tpe.isTerm then registerType(tpe.widenTermRefExpr)
660663
case _ =>
661664
}
662665

@@ -782,7 +785,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
782785
case t: ThisType => thisProxy.getOrElse(t.cls, t)
783786
case t: TypeRef => paramProxy.getOrElse(t, mapOver(t))
784787
case t: SingletonType =>
785-
if t.termSymbol.isAllOf(Inline | Param) then mapOver(t.widenTermRefExpr)
788+
if t.termSymbol.isAllOf(Inline | Param) then apply(t.widenTermRefExpr)
786789
else paramProxy.getOrElse(t, mapOver(t))
787790
case t => mapOver(t)
788791
}

tests/pos/i12379a.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
inline def convFail[Of, From](inline from : From) : Unit =
2+
val c = compiletime.summonInline[Conversion[from.type, Of]]
3+
4+
inline def convOK[Of, From](inline from : From)(using c : Conversion[from.type, Of]) : Unit = {}
5+
6+
class Bar[T](value : T)
7+
given [T <: Int] : Conversion[T, Bar[T]] = Bar(_)
8+
9+
@main def main : Unit = {
10+
convOK[Bar[1],1](1)
11+
convFail[Bar[1],1](1) //causes error
12+
}

tests/pos/i12379b.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
inline def convFail[Of, From](inline from : From) : Unit =
2+
val c = compiletime.summonInline[Conversion[From, Of]]
3+
4+
inline def convOK[Of, From](inline from : From)(using c : Conversion[From, Of]) : Unit = {}
5+
6+
class Bar[T](value : T)
7+
given [T <: Int] : Conversion[T, Bar[T]] = Bar(_)
8+
9+
@main def main : Unit = {
10+
convOK[Bar[1],1](1)
11+
convFail[Bar[1],1](1) //causes error
12+
}

0 commit comments

Comments
 (0)