Skip to content

Commit 2517f38

Browse files
committed
Fix implicit type used for conversions, as seen from usage
Using the minimisation of the specs2 failure that occurred in CI, the conversion desired is `Conversion[String, Bar.this.Data]`. But if we use the given's symbol info, we end up with the type `Conversion[String, Foo.this.Data]` which the generated tree will fail to adapt to. Using the widening of the implicit candidate's TermRef will yield a method type, as seen from the right prefix - `Bar.this.Data`.
1 parent c32adc2 commit 2517f38

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ trait Implicits:
11381138
case _ => pt
11391139
case _ => NoType
11401140
def tryConversion(using Context) = {
1141-
val restpeConv = if ref.symbol.is(Given) then conversionResultType(ref.symbol.info) else NoType
1141+
val restpeConv = if ref.symbol.is(Given) then conversionResultType(ref.widenTermRefExpr) else NoType
11421142
val untpdConv =
11431143
if restpeConv.exists then
11441144
untpd.Select(

tests/pos/i15867.specs2.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Foo:
2+
given Conversion[String, Data] with
3+
def apply(str: String): Data = new Data(str)
4+
5+
class Data(str: String):
6+
def |(str: String) = new Data(this.str + str)
7+
8+
class Bar extends Foo:
9+
"str" | "ing"

0 commit comments

Comments
 (0)