Skip to content

Commit 50a2d66

Browse files
Merge pull request #11007 from dotty-staging/fix-#9329
Check for unimplemented abstract override members
2 parents b0f7e26 + 6b424fd commit 50a2d66

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ object Flags {
530530

531531
// ------- Other flag sets -------------------------------------
532532

533+
val NotConcrete: FlagSet = AbsOverride | Deferred
533534
val AbstractFinal: FlagSet = Abstract | Final
534535
val AbstractOverride: FlagSet = Abstract | Override
535536
val AbstractSealed: FlagSet = Abstract | Sealed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,10 @@ object RefChecks {
524524

525525
def isImplemented(mbr: Symbol) =
526526
val mbrType = clazz.thisType.memberInfo(mbr)
527-
extension (sym: Symbol) def isConcrete = sym.exists && !sym.is(Deferred)
527+
def isConcrete(sym: Symbol) = sym.exists && !sym.isOneOf(NotConcrete)
528528
clazz.nonPrivateMembersNamed(mbr.name)
529529
.filterWithPredicate(
530-
impl => impl.symbol.isConcrete && mbrType.matchesLoosely(impl.info))
530+
impl => isConcrete(impl.symbol) && mbrType.matchesLoosely(impl.info))
531531
.exists
532532

533533
/** The term symbols in this class and its baseclasses that are
@@ -641,7 +641,11 @@ object RefChecks {
641641

642642
undefined(s"\n(Note that ${pa.show} does not match ${pc.show}$addendum)")
643643
case xs =>
644-
undefined(s"\n(The class implements a member with a different type: ${concrete.showDcl})")
644+
undefined(
645+
if concrete.symbol.is(AbsOverride) then
646+
s"\n(The class implements ${concrete.showDcl} but that definition still needs an implementation)"
647+
else
648+
s"\n(The class implements a member with a different type: ${concrete.showDcl})")
645649
}
646650
case Nil =>
647651
undefined("")

tests/neg/i9329.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Error: tests/neg/i9329.scala:8:6 ------------------------------------------------------------------------------------
2+
8 |class GrandSon extends Son // error
3+
| ^
4+
| class GrandSon needs to be abstract, since def name: => String is not defined
5+
| (The class implements abstract override def name: => String but that definition still needs an implementation)

tests/neg/i9329.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait Parent {
2+
def name: String
3+
}
4+
trait Son extends Parent {
5+
abstract override def name = ""
6+
def parentName = super.name
7+
}
8+
class GrandSon extends Son // error

0 commit comments

Comments
 (0)