Skip to content

Fix #3692: Generalize implicit function subtyping. #3704

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 1 commit into from
Jan 13, 2018
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
case tp1: MethodOrPoly =>
(tp1.signature consistentParams tp2.signature) &&
matchingParams(tp1, tp2) &&
tp1.isImplicitMethod == tp2.isImplicitMethod &&
(!tp2.isImplicitMethod || tp1.isImplicitMethod) &&
isSubType(tp1.resultType, tp2.resultType.subst(tp2, tp1))
case _ =>
false
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ object ProtoTypes {
normalize(et.resultType, pt)
case wtp =>
val iftp = defn.asImplicitFunctionType(wtp)
if (iftp.exists) normalize(iftp.argInfos.last, pt) else tp
if (iftp.exists) normalize(iftp.dropDependentRefinement.argInfos.last, pt) else tp
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i2000.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object test1 {
class C[A] { def foo(a: A) = "c" }
class D extends C[String] { override def foo(implicit s: String) = "d" } // error
class D extends C[String] { override def foo(implicit s: String) = "d" } // used to be error, now ok
}

object test2 {
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i3692.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class C { type T }

object Main {

//val a: implicit Int => Int = implicit (x: Int) => x
//val b: Int => Int = a

def main(args: Array[String]): Unit = {
val choose: implicit (c: C) => Set[Int] = Set.empty
val b0: (C) => Set[Int] = choose
val b1: (c: C) => Set[Int] = choose
def applyF(f: (c: C) => Set[Int]) = f(new C{type T=Int})
//applyF(choose)
}
}