Skip to content

Commit

Permalink
Fix implicit type used for conversions, as seen from usage
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
dwijnand committed Jun 2, 2023
1 parent c32adc2 commit 2517f38
Show file tree
Hide file tree
Showing 2 changed files with 10 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 @@ -1138,7 +1138,7 @@ trait Implicits:
case _ => pt
case _ => NoType
def tryConversion(using Context) = {
val restpeConv = if ref.symbol.is(Given) then conversionResultType(ref.symbol.info) else NoType
val restpeConv = if ref.symbol.is(Given) then conversionResultType(ref.widenTermRefExpr) else NoType
val untpdConv =
if restpeConv.exists then
untpd.Select(
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i15867.specs2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Foo:
given Conversion[String, Data] with
def apply(str: String): Data = new Data(str)

class Data(str: String):
def |(str: String) = new Data(this.str + str)

class Bar extends Foo:
"str" | "ing"

0 comments on commit 2517f38

Please sign in to comment.