dmd icon indicating copy to clipboard operation
dmd copied to clipboard

fix Issue 21298 - Missing error when overriding interface method with…

Open WalterBright opened this issue 4 years ago • 4 comments

…out in contract with class method with contract

WalterBright avatar Dec 01 '20 08:12 WalterBright

Thanks for your pull request, @WalterBright!

Bugzilla references

Auto-close Bugzilla Severity Description
21298 minor Missing error when overriding interface method without in contract with class method with contract

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#12013"

dlang-bot avatar Dec 01 '20 08:12 dlang-bot

This has failures in phobos. Should this require a deprecation?

thewilsonator avatar Dec 01 '20 08:12 thewilsonator

The errors are happening because the overridden function is abstract and so has no implementation. But before worrying about that, as I wrote in the bugzilla issue, I'm not sure the issue is even valid.

WalterBright avatar Dec 01 '20 09:12 WalterBright

The issue is valid. Look at this example:

interface I
{
  int foo(int i) out (r; r>0);
}

class C : I
{
  override int foo(int i) in (i > 0) { return i; }
}

This results in: "Error: function onlineapp.C.foo cannot have an in contract when overridden function onlineapp.I.foo does not have an in contract"

If this works, then I don't see any reason why it would simply compile when the contract is missing in the interface function.

The way forward would be to issue a deprecation.

RazvanN7 avatar Jan 06 '21 11:01 RazvanN7