diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 4e903d519af8..ed2d0dfed0a8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -174,14 +174,19 @@ object Implicits { * Note that we always take the underlying type of a singleton type as the argument * type, so that we get a reasonable implicit cache hit ratio. */ - def adjustSingletonArg(tp: Type): Type = tp.widenSingleton match { + def adjustSingletonArg(tp: Type): Type = tp.widenSingleton match case tp: PolyType => val res = adjustSingletonArg(tp.resType) - if (res `eq` tp.resType) tp else tp.derivedLambdaType(resType = res) + if res eq tp.resType then tp else tp.derivedLambdaType(resType = res) case tp: MethodType => tp.derivedLambdaType(paramInfos = tp.paramInfos.mapConserve(widenSingleton)) - case _ => tp - } + case _ => + tp.baseType(defn.ConversionClass) match + case app @ AppliedType(tycon, from :: rest) => + val wideFrom = from.widenSingleton + if wideFrom ne from then app.derivedAppliedType(tycon, wideFrom :: rest) + else tp + case _ => tp var ckind = if (!ref.symbol.isAccessibleFrom(ref.prefix)) Candidate.None @@ -1384,7 +1389,7 @@ trait Implicits { self: Typer => untpd.Select( untpd.TypedSplice( adapt(generated, - defn.ConversionClass.typeRef.appliedTo(argument.tpe.widen, pt), + defn.ConversionClass.typeRef.appliedTo(argument.tpe, pt), locked)), nme.apply) else untpdGenerated diff --git a/tests/pos/i7413.scala b/tests/pos/i7413.scala new file mode 100644 index 000000000000..58c95529a8c2 --- /dev/null +++ b/tests/pos/i7413.scala @@ -0,0 +1,24 @@ +import scala.language.implicitConversions + +trait Fixture[A] extends Conversion[0, A] + +trait TestFramework[A] { + def (testName: String) in (test: (given Fixture[A]) => Unit): Unit = ??? +} + +trait Greeter { + def greet(name: String): String = s"Hello $name" +} + +case class MyFixture(name: String, greeter: Greeter) + +object Test1 with + given conv: Conversion[0, Greeter] + def apply(x: 0): Greeter = ??? + val g: Greeter = 0 + +class MyTest extends TestFramework[MyFixture] { + "say hello" in { + assert(0.greeter.greet(0.name) == s"Hello ${0.name}") + } +}