Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/pos/i7413.scala
Original file line number Diff line number Diff line change
@@ -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}")
}
}