Skip to content

Fix #2000: Make implicit and non-implicit functions incomparable #2014

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 3 commits into from
Feb 22, 2017
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 @@ -489,7 +489,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
case tp1 @ MethodType(_, formals1) =>
(tp1.signature consistentParams tp2.signature) &&
matchingParams(formals1, formals2, tp1.isJava, tp2.isJava) &&
(!tp1.isImplicit || tp2.isImplicit) && // non-implicit functions shadow implicit ones
(tp1.isImplicit == tp2.isImplicit) &&
isSubType(tp1.resultType, tp2.resultType.subst(tp2, tp1))
case _ =>
false
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class tests extends CompilerTest {
@Test def neg_autoTupling = compileFile(negCustomArgs, "autoTuplingTest", args = "-language:noAutoTupling" :: Nil)
@Test def neg_i1050 = compileFile(negCustomArgs, "i1050", List("-strict"))
@Test def neg_i1240 = compileFile(negCustomArgs, "i1240")(allowDoubleBindings)
@Test def neg_i2002 = compileFile(negCustomArgs, "i2002")(allowDoubleBindings)

val negTailcallDir = negDir + "tailcall/"
@Test def neg_tailcall_t1672b = compileFile(negTailcallDir, "t1672b")
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/customArgs/i2002.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Test {
def foo(i: Int): Int = i
def foo(implicit i: Int): Int = i // error
}
23 changes: 23 additions & 0 deletions tests/neg/i2000.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
object test1 {
class C[A] { def foo(a: A) = "c" }
class D extends C[String] { override def foo(implicit s: String) = "d" } // error
}

object test2 {
class C[A] { final def foo(a: A) = "c" }
class D extends C[String] { def foo(implicit s: String) = "d" } // error
object Test {
def main(args: Array[String]) =
new D
}
}

object test3 {
class A {
def foo(implicit i: Int): Int = i + i
}

class B extends A {
override def foo(i: Int): Int = i // error
}
}