[Issue 21689] New: Contracts (in/out) is not checked when for interfaces methods

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Mar 8 10:48:47 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21689

          Issue ID: 21689
           Summary: Contracts (in/out) is not checked when for interfaces
                    methods
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: dlang.org
          Assignee: nobody at puremagic.com
          Reporter: cr at tagion.org

Created attachment 1820
  --> https://issues.dlang.org/attachment.cgi?id=1820&action=edit
Example

I know that this has been reported as a bug before but it was declined as a
bug.
I reported it some years back also and I found two other similar reports
issue-12227 and issue-21298.

I continue to fall into this trap of this feature when I use an interface
and nearly all of my colleagues which new to D fall into this.

It is not logical that the pre/post-condition is not functional just because it
comes from an interface.

In my option, class C and CI should both execute the pre-condition, or at least
the compiler should make an error and tell that preconditions are not allowed
when the function is defined in an interface.

```
interface I {
    int func(int x);
}

class CI : I {
    int func(int x)
        in {
            assert(x > 0);
        }
    do {
        return x*x;
    }
}

class C {
    int func(int x)
        in {
            assert(x > 0);
        }
    do {
        return x*x;
    }
}
```

Thank you for the good work.

--


More information about the Digitalmars-d-bugs mailing list