Skip to content

Commit a252641

Browse files
authored
Merge pull request #7566 from dotty-staging/fix-#7413
Fix #7413: Adjust singleton arguments for new conversions
2 parents 3d42550 + 9acf39d commit a252641

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,19 @@ object Implicits {
174174
* Note that we always take the underlying type of a singleton type as the argument
175175
* type, so that we get a reasonable implicit cache hit ratio.
176176
*/
177-
def adjustSingletonArg(tp: Type): Type = tp.widenSingleton match {
177+
def adjustSingletonArg(tp: Type): Type = tp.widenSingleton match
178178
case tp: PolyType =>
179179
val res = adjustSingletonArg(tp.resType)
180-
if (res `eq` tp.resType) tp else tp.derivedLambdaType(resType = res)
180+
if res eq tp.resType then tp else tp.derivedLambdaType(resType = res)
181181
case tp: MethodType =>
182182
tp.derivedLambdaType(paramInfos = tp.paramInfos.mapConserve(widenSingleton))
183-
case _ => tp
184-
}
183+
case _ =>
184+
tp.baseType(defn.ConversionClass) match
185+
case app @ AppliedType(tycon, from :: rest) =>
186+
val wideFrom = from.widenSingleton
187+
if wideFrom ne from then app.derivedAppliedType(tycon, wideFrom :: rest)
188+
else tp
189+
case _ => tp
185190

186191
var ckind =
187192
if (!ref.symbol.isAccessibleFrom(ref.prefix)) Candidate.None
@@ -1384,7 +1389,7 @@ trait Implicits { self: Typer =>
13841389
untpd.Select(
13851390
untpd.TypedSplice(
13861391
adapt(generated,
1387-
defn.ConversionClass.typeRef.appliedTo(argument.tpe.widen, pt),
1392+
defn.ConversionClass.typeRef.appliedTo(argument.tpe, pt),
13881393
locked)),
13891394
nme.apply)
13901395
else untpdGenerated

tests/pos/i7413.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import scala.language.implicitConversions
2+
3+
trait Fixture[A] extends Conversion[0, A]
4+
5+
trait TestFramework[A] {
6+
def (testName: String) in (test: (given Fixture[A]) => Unit): Unit = ???
7+
}
8+
9+
trait Greeter {
10+
def greet(name: String): String = s"Hello $name"
11+
}
12+
13+
case class MyFixture(name: String, greeter: Greeter)
14+
15+
object Test1 with
16+
given conv: Conversion[0, Greeter]
17+
def apply(x: 0): Greeter = ???
18+
val g: Greeter = 0
19+
20+
class MyTest extends TestFramework[MyFixture] {
21+
"say hello" in {
22+
assert(0.greeter.greet(0.name) == s"Hello ${0.name}")
23+
}
24+
}

0 commit comments

Comments
 (0)