Skip to content

Commit bcd3c1f

Browse files
committed
Fix #1531: Ignore private members when looking for abstract ones
Private members do not override abstract ones. So when looking for abstract members we need to search with `nonPrivateMember`, not `member`. Fixes #1531. Review by @smarter.
1 parent 8bfaada commit bcd3c1f

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/dotty/tools/dotc/core/Types.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,13 +615,13 @@ object Types {
615615
/** The set of abstract term members of this type. */
616616
final def abstractTermMembers(implicit ctx: Context): Seq[SingleDenotation] = track("abstractTermMembers") {
617617
memberDenots(abstractTermNameFilter,
618-
(name, buf) => buf ++= member(name).altsWith(_ is Deferred))
618+
(name, buf) => buf ++= nonPrivateMember(name).altsWith(_ is Deferred))
619619
}
620620

621621
/** The set of abstract type members of this type. */
622622
final def abstractTypeMembers(implicit ctx: Context): Seq[SingleDenotation] = track("abstractTypeMembers") {
623623
memberDenots(abstractTypeNameFilter,
624-
(name, buf) => buf += member(name).asSingleDenotation)
624+
(name, buf) => buf += nonPrivateMember(name).asSingleDenotation)
625625
}
626626

627627
/** The set of abstract type members of this type. */
@@ -3756,7 +3756,7 @@ object Types {
37563756
object abstractTypeNameFilter extends NameFilter {
37573757
def apply(pre: Type, name: Name)(implicit ctx: Context): Boolean =
37583758
name.isTypeName && {
3759-
val mbr = pre.member(name)
3759+
val mbr = pre.nonPrivateMember(name)
37603760
(mbr.symbol is Deferred) && mbr.info.isInstanceOf[RealTypeBounds]
37613761
}
37623762
}
@@ -3773,7 +3773,7 @@ object Types {
37733773
/** A filter for names of deferred term definitions of a given type */
37743774
object abstractTermNameFilter extends NameFilter {
37753775
def apply(pre: Type, name: Name)(implicit ctx: Context): Boolean =
3776-
name.isTermName && (pre member name).hasAltWith(_.symbol is Deferred)
3776+
name.isTermName && pre.nonPrivateMember(name).hasAltWith(_.symbol is Deferred)
37773777
}
37783778

37793779
object typeNameFilter extends NameFilter {

src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ object RefChecks {
487487
// abstract method, and a cursory examination of the difference reveals
488488
// something obvious to us, let's make it more obvious to them.
489489
val abstractParams = underlying.info.firstParamTypes
490-
val matchingName = clazz.info.member(underlying.name).alternatives
490+
val matchingName = clazz.info.nonPrivateMember(underlying.name).alternatives
491491
val matchingArity = matchingName filter { m =>
492492
!m.symbol.is(Deferred) &&
493493
m.info.firstParamTypes.length == abstractParams.length

tests/neg/i1531.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait T {
2+
def f: Int
3+
}
4+
5+
class A(f: Int) extends T // error: class A needs to be abstract
6+

0 commit comments

Comments
 (0)