Skip to content

Commit

Permalink
Apply implicit conversion from derived Conversion instance defined as…
Browse files Browse the repository at this point in the history
… implicit rather than given
  • Loading branch information
prolativ committed Oct 16, 2024
1 parent 78cff1b commit a4387db
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ trait Implicits:
case _ => info.derivesFrom(defn.ConversionClass)
def tryConversion(using Context) = {
val untpdConv =
if ref.symbol.is(Given) && producesConversion(ref.symbol.info) then
if ref.symbol.isOneOf(GivenOrImplicit) && producesConversion(ref.symbol.info) then
untpd.Select(
untpd.TypedSplice(
adapt(generated,
Expand Down
33 changes: 33 additions & 0 deletions tests/pos/i21757.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
object ConversionChain {

class X(val value: Int)

class Y(val x: X)

class Z(val y: Y)

trait Conv[A, B] extends Conversion[A, B]

given xy: Conv[X, Y] = { (x: X) => new Y(x) }

given yz: Conv[Y, Z] = { (y: Y) => new Z(y) }

object ConvUtils {
implicit def hypotheticalSyllogism[A, B, C]( // implicit def instead of given
using
ab: Conv[A, B],
bc: Conv[B, C]
): Conv[A, C] = {

new Conv[A, C] {
def apply(a: A): C = bc(ab(a))
}
}
}
import ConvUtils.hypotheticalSyllogism

def test(): Unit = {
val x = new X(42)
val z: Z = x
}
}

0 comments on commit a4387db

Please sign in to comment.