www.digitalmars.com         C & C++   DMDScript  

D - Compiler wants abstract class to implement whole interface, bug?

When I try to compile an abstract class that subclasses an
interface (see code below) but does not implement it
completely, I get the following error:

\dmd\bin\dmd -c -od\dev\d\util\bin -I\dev\d\util\src
\dev\d\util\src\acr\test\Foo
\dmd\bin\dmd -c -od\dev\d\util\bin -I\dev\d\util\src
\dev\d\util\src\acr\test\AbstractFoo
\dev\d\util\src\acr\test\AbstractFoo.d: class AbstractFoo interface function
Foo.one is not implemented
make: *** [acr.test] Error 1

Then I try uncomment "Version 1" (in file AbstractFoo.d),
which does not work either (and would be terrible if that was
the accepted way, since that would mean rewriting abstract
functions all over).

Then I try "Version 2", which compiles, and I assume it's
a bug, since the function is declared abstract and nevertheless
has a body.

Then I get to "Version 3", which does not compile because the
function want something returning from it.  Shouldn't a throw
be return enough?

Finally, "Version 4" does compile, but I have defeated the
purpose of having an "AbstractFoo" in the middle.

Ideas or comments?  Thanks.




Foo.d ----------------------------------------

module acr.test.Foo;

public interface Foo {
    int one(Object o);
    int two(Object o);
}


AbstractFoo.d ----------------------------------------

module acr.test.AbstractFoo;
import acr.test.Foo;


public abstract class AbstractFoo : Foo {
    // Version 1
    // abstract int one(Object o);

    // Version 2
    // abstract int one(Object o) { return 1; }

    // Version 3
    // int one(Object o) { throw new Error("should never be here"); }

    // Version 4
    // int one(Object o) { throw new Error("should never be here"); return
1; }

    int two(Object o) { return 2; }
}


RealFoo.d ----------------------------------------

module acr.test.RealFoo;
import acr.test.AbstractFoo;


public class RealFoo : AbstractFoo {
    int one(Object o) { return 1; }
    int two(Object o) { return super.two(o); }
    int three(Object o) { return 3; }
}
Feb 03 2004