Skip to content

Commit 8a826ee

Browse files
authored
Merge pull request #2014 from dotty-staging/fix-#2002
Fix #2000: Make implicit and non-implicit functions incomparable
2 parents 5c7ef22 + 5e53ff3 commit 8a826ee

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
489489
case tp1 @ MethodType(_, formals1) =>
490490
(tp1.signature consistentParams tp2.signature) &&
491491
matchingParams(formals1, formals2, tp1.isJava, tp2.isJava) &&
492-
(!tp1.isImplicit || tp2.isImplicit) && // non-implicit functions shadow implicit ones
492+
(tp1.isImplicit == tp2.isImplicit) &&
493493
isSubType(tp1.resultType, tp2.resultType.subst(tp2, tp1))
494494
case _ =>
495495
false

compiler/test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ class tests extends CompilerTest {
184184
@Test def neg_autoTupling = compileFile(negCustomArgs, "autoTuplingTest", args = "-language:noAutoTupling" :: Nil)
185185
@Test def neg_i1050 = compileFile(negCustomArgs, "i1050", List("-strict"))
186186
@Test def neg_i1240 = compileFile(negCustomArgs, "i1240")(allowDoubleBindings)
187+
@Test def neg_i2002 = compileFile(negCustomArgs, "i2002")(allowDoubleBindings)
187188

188189
val negTailcallDir = negDir + "tailcall/"
189190
@Test def neg_tailcall_t1672b = compileFile(negTailcallDir, "t1672b")

tests/neg/customArgs/i2002.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Test {
2+
def foo(i: Int): Int = i
3+
def foo(implicit i: Int): Int = i // error
4+
}

tests/neg/i2000.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
object test1 {
2+
class C[A] { def foo(a: A) = "c" }
3+
class D extends C[String] { override def foo(implicit s: String) = "d" } // error
4+
}
5+
6+
object test2 {
7+
class C[A] { final def foo(a: A) = "c" }
8+
class D extends C[String] { def foo(implicit s: String) = "d" } // error
9+
object Test {
10+
def main(args: Array[String]) =
11+
new D
12+
}
13+
}
14+
15+
object test3 {
16+
class A {
17+
def foo(implicit i: Int): Int = i + i
18+
}
19+
20+
class B extends A {
21+
override def foo(i: Int): Int = i // error
22+
}
23+
}

0 commit comments

Comments
 (0)