Skip to content

Commit a4387db

Browse files
committed
Apply implicit conversion from derived Conversion instance defined as implicit rather than given
1 parent 78cff1b commit a4387db

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Implicits.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ trait Implicits:
11761176
case _ => info.derivesFrom(defn.ConversionClass)
11771177
def tryConversion(using Context) = {
11781178
val untpdConv =
1179-
if ref.symbol.is(Given) && producesConversion(ref.symbol.info) then
1179+
if ref.symbol.isOneOf(GivenOrImplicit) && producesConversion(ref.symbol.info) then
11801180
untpd.Select(
11811181
untpd.TypedSplice(
11821182
adapt(generated,

Diff for: tests/pos/i21757.scala

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
object ConversionChain {
2+
3+
class X(val value: Int)
4+
5+
class Y(val x: X)
6+
7+
class Z(val y: Y)
8+
9+
trait Conv[A, B] extends Conversion[A, B]
10+
11+
given xy: Conv[X, Y] = { (x: X) => new Y(x) }
12+
13+
given yz: Conv[Y, Z] = { (y: Y) => new Z(y) }
14+
15+
object ConvUtils {
16+
implicit def hypotheticalSyllogism[A, B, C]( // implicit def instead of given
17+
using
18+
ab: Conv[A, B],
19+
bc: Conv[B, C]
20+
): Conv[A, C] = {
21+
22+
new Conv[A, C] {
23+
def apply(a: A): C = bc(ab(a))
24+
}
25+
}
26+
}
27+
import ConvUtils.hypotheticalSyllogism
28+
29+
def test(): Unit = {
30+
val x = new X(42)
31+
val z: Z = x
32+
}
33+
}

0 commit comments

Comments
 (0)