[Issue 11835] Assert not thrown from contract

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Dec 30 18:01:44 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11835



--- Comment #6 from Stewart Gordon <smjg at iname.com> 2013-12-30 18:01:40 PST ---
(In reply to comment #4)
> Ok, now I see why it is working like that, but consider this sample:
> 
> interface IFoo
> {
>         void test()
>         in
>         {
>                 writeln("IFoo.test");
>                 assert(false);
>         }
> }
> 
> class Foo : IFoo
> {
>         void test()
>         in
>         {
>                 writeln("Foo.test");
>         }
>         body{}
> }
> 
> class Bar : IFoo
> {
>         void test()
>         in
>         {
>                 writeln("Bar.test");
>         }
>         body{}
> }
> 
> as it works now it means, that interface contract will never throw 
> an AssertError, because Foo and Bar tests passes.
> 
> What is then the point to define contract in the interface if I 
> have to set the same in class definitions of that interface?

To define the legal inputs to IFoo.test, and hence the minimum that
implementations of the method must support.

> here I will definitelly expect that contract defined in interface 
> will be used to check input of actual methods.

Foo.test or Bar.test could be called on an object reference of type Foo or Bar.
 Then it is allowed to use the wider range of inputs that the class-specific
version supports.

At the moment, the way to just inherit the contract from a superclass or
interface is to use

    in { assert (false); }

> It just seems weird to me. For example if I write a library with 
> the public interface or abstract class and want to check input 
> params of it so when other project uses it it will check if it is 
> used properly. But as it works now, this is not possible.

See issue 6857.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list