Skip to content

Commit 74cfd84

Browse files
authored
Merge pull request #9139 from dotty-staging/polymorphic-override
Fix #9109: More precise override check
2 parents 011b3a7 + 7964d17 commit 74cfd84

File tree

8 files changed

+20
-6
lines changed

8 files changed

+20
-6
lines changed

compiler/src/dotty/tools/dotc/transform/OverridingPairs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object OverridingPairs {
4040
* relative to <base>.this do
4141
*/
4242
protected def matches(sym1: Symbol, sym2: Symbol): Boolean =
43-
sym1.isType || self.memberInfo(sym1).matches(self.memberInfo(sym2))
43+
sym1.isType || sym1.asSeenFrom(self).matches(sym2.asSeenFrom(self))
4444

4545
/** The symbols that can take part in an overriding pair */
4646
private val decls = {

tests/explicit-nulls/neg/override-java-object-arg2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Foo {
55

66
def bar(): Unit = {
77
val listener4 = new NotificationListener() { // error: duplicate symbol error
8-
def handleNotification(n: Notification|Null, emitter: Object): Unit = {
8+
def handleNotification(n: Notification|Null, emitter: Object): Unit = { // error
99
}
1010
}
1111
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
case class Foo1(erased x: Int) // error
1+
case class Foo1(erased x: Int) // error // error

tests/neg/i7597.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
object Test extends App {
22
def foo[S <: String]: String => Int =
3-
new (String => Int) { def apply(s: S): Int = 0 } // error
3+
new (String => Int) { def apply(s: S): Int = 0 } // error // error
44

55
trait Fn[A, B] {
66
def apply(x: A): B
77
}
88

99
class C[S <: String] extends Fn[String, Int] { // error
10-
def apply(s: S): Int = 0
10+
def apply(s: S): Int = 0 // error
1111
}
1212

1313
foo("")

tests/pos-java-interop/i9109/A.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public class A {
2+
public <T extends java.io.Serializable> void foo(T x) {}
3+
public <T extends Cloneable> void foo(T x) {}
4+
}

tests/pos-java-interop/i9109/B.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class B extends A {
2+
override def foo[T <: Serializable](x: T): Unit = {}
3+
}

tests/pos/i9109.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class A {
2+
def foo[T <: Serializable](x: T): Unit = {}
3+
def foo[T <: Cloneable](x: T): Unit = {}
4+
}
5+
class B extends A {
6+
override def foo[T <: Serializable](x: T): Unit = {}
7+
}

tests/pos/zoo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait Animal {
1414
trait Cow extends Animal {
1515
type IsMeat = Any
1616
type Food <: Grass
17-
def eats(food: Grass): Unit
17+
def eats(food: Food): Unit
1818
def gets: Food
1919
}
2020
trait Lion extends Animal {

0 commit comments

Comments
 (0)