Skip to content

Fix #7413: Adjust singleton arguments for new conversions #7566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2019
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}")
}
}