Skip to content

Commit 668a637

Browse files
committed
Fix #5578: Refine matches condition
`matches` incorrectly returned a match if two members differed only in their type parameters.
1 parent fcc35d2 commit 668a637

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,12 @@ object Denotations {
10711071

10721072
final def matches(other: SingleDenotation)(implicit ctx: Context): Boolean = {
10731073
val d = signature.matchDegree(other.signature)
1074-
d == Signature.FullMatch ||
1075-
d >= Signature.ParamMatch && info.matches(other.info)
1074+
(// fast path: signatures are the same and neither denotation is a PolyType
1075+
// For polytypes, signatures alone do not tell us enough to be sure about matching.
1076+
d == Signature.FullMatch && !info.isInstanceOf[PolyType] && !other.info.isInstanceOf[PolyType]
1077+
||
1078+
// slow path
1079+
d >= Signature.ParamMatch && info.matches(other.info))
10761080
}
10771081

10781082
def mapInherited(ownDenots: PreDenotation, prevDenots: PreDenotation, pre: Type)(implicit ctx: Context): SingleDenotation =

tests/neg/i5578.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait P[A]{
2+
def a[T]: A
3+
}
4+
class C extends P[Int]{ // error: class C needs to be abstract
5+
def a = 1
6+
}
7+
object O{
8+
def main(args: Array[String]) = {
9+
val p: P[Int] = new C
10+
println(p.a)
11+
}
12+
}

0 commit comments

Comments
 (0)