Formal model for defender method resolution

Neal Gafter neal at
Fri Jan 28 15:55:00 PST 2011

On Fri, Jan 28, 2011 at 3:17 PM, Alex Buckley <alex.buckley at>wrote:

> On 1/28/2011 12:30 PM, Neal Gafter wrote:
> > Your proposal here (B.m inherits A's default) feels ok to me, but I could
> > see it going the other way.  Here's why.
> >
> > In the more general case with covariant overriding
> >
> > interface A {
> >     A f() { ... }
> > }
> > interface B extends A {
> >     B f();
> > }
> >
> > I don't think there needs to be any error on B.  At compile-time, any
> class
> > that implements B will have to provide an implementation for B.f() [it is
> > after all abstract], so the error on B serves little purpose.
> But A and B could have gained f after the class that implements B was
> compiled. In which case, we must ensure that C responds to
> invokeinterface A.f()A or invokeinterface B.f()B with an instance of B
> or deeper.
> If there's no error for the B above, and yet B.f _does not_ inherit
> A.f's default (as you suggest), then invokeinterface B.f()B; on a C will
> resolve then ... what? Die due to no f impl? Or execute A's f impl,
> possibly leading to unsoundness?

Die due to no f impl, exactly as it does today.  In this case it is
irrelevant that one of the newly added methods has a default, as that
default could not possibly be the one that the call resolves to.  This is a
situation that occurs today and that is indeed what happens.

If there's no error for B, and B.f _does_ inherit A.f's default, then
> invokeinterface B.f()B on a C may return an A that's not a B, and we
> definitely have unsoundness.

Agreed!  Which is why B.f should not inherit A.f's default.

> So either there should be an error on B;

Huh?  Why?  This is a simple case of reabstraction.  There's nothing wrong
with B.  There might or might not be something wrong with some further
derived type, but B is fine.

> or no error yet _B.f inherits
> A.f's default and the inherited defender is typechecked in its new
> environment_.

Huh?  Why?  When you reabstract a method, it has no implementation to
inherit or check.

More information about the lambda-dev mailing list