Skip to content

Commit f22c662

Browse files
authored
Merge pull request #3704 from dotty-staging/fix-#3692
Fix #3692: Generalize implicit function subtyping.
2 parents f802abf + 91a6f57 commit f22c662

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
518518
case tp1: MethodOrPoly =>
519519
(tp1.signature consistentParams tp2.signature) &&
520520
matchingParams(tp1, tp2) &&
521-
tp1.isImplicitMethod == tp2.isImplicitMethod &&
521+
(!tp2.isImplicitMethod || tp1.isImplicitMethod) &&
522522
isSubType(tp1.resultType, tp2.resultType.subst(tp2, tp1))
523523
case _ =>
524524
false

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ object ProtoTypes {
470470
normalize(et.resultType, pt)
471471
case wtp =>
472472
val iftp = defn.asImplicitFunctionType(wtp)
473-
if (iftp.exists) normalize(iftp.argInfos.last, pt) else tp
473+
if (iftp.exists) normalize(iftp.dropDependentRefinement.argInfos.last, pt) else tp
474474
}
475475
}
476476

tests/neg/i2000.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object test1 {
22
class C[A] { def foo(a: A) = "c" }
3-
class D extends C[String] { override def foo(implicit s: String) = "d" } // error
3+
class D extends C[String] { override def foo(implicit s: String) = "d" } // used to be error, now ok
44
}
55

66
object test2 {

tests/pos/i3692.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class C { type T }
2+
3+
object Main {
4+
5+
//val a: implicit Int => Int = implicit (x: Int) => x
6+
//val b: Int => Int = a
7+
8+
def main(args: Array[String]): Unit = {
9+
val choose: implicit (c: C) => Set[Int] = Set.empty
10+
val b0: (C) => Set[Int] = choose
11+
val b1: (c: C) => Set[Int] = choose
12+
def applyF(f: (c: C) => Set[Int]) = f(new C{type T=Int})
13+
//applyF(choose)
14+
}
15+
}

0 commit comments

Comments
 (0)