Skip to content

Fix #12379: Handle singleton types properly in proxy registeration #12398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
paramBinding.get(tpe.name) match
case Some(bound) => paramProxy(tpe) = bound
case _ => // can happen for params bound by type-lambda trees.

// The widened type may contain param types too (see tests/pos/i12379a.scala)
if tpe.isTerm then registerType(tpe.widenTermRefExpr)
case _ =>
}

Expand Down Expand Up @@ -782,7 +785,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
case t: ThisType => thisProxy.getOrElse(t.cls, t)
case t: TypeRef => paramProxy.getOrElse(t, mapOver(t))
case t: SingletonType =>
if t.termSymbol.isAllOf(Inline | Param) then mapOver(t.widenTermRefExpr)
if t.termSymbol.isAllOf(Inline | Param) then apply(t.widenTermRefExpr)
else paramProxy.getOrElse(t, mapOver(t))
case t => mapOver(t)
}
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/i12379a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
inline def convFail[Of, From](inline from : From) : Unit =
val c = compiletime.summonInline[Conversion[from.type, Of]]

inline def convOK[Of, From](inline from : From)(using c : Conversion[from.type, Of]) : Unit = {}

class Bar[T](value : T)
given [T <: Int] : Conversion[T, Bar[T]] = Bar(_)

@main def main : Unit = {
convOK[Bar[1],1](1)
convFail[Bar[1],1](1) //causes error
}
12 changes: 12 additions & 0 deletions tests/pos/i12379b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
inline def convFail[Of, From](inline from : From) : Unit =
val c = compiletime.summonInline[Conversion[From, Of]]

inline def convOK[Of, From](inline from : From)(using c : Conversion[From, Of]) : Unit = {}

class Bar[T](value : T)
given [T <: Int] : Conversion[T, Bar[T]] = Bar(_)

@main def main : Unit = {
convOK[Bar[1],1](1)
convFail[Bar[1],1](1) //causes error
}