Bug 21298 – Missing error when overriding interface method without in contract with class method with contract

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-10-08T10:52:06Z
Last change time
2024-12-13T19:11:57Z
Keywords
industry, pull
Assigned to
No Owner
Creator
FeepingCreature
See also
https://issues.dlang.org/show_bug.cgi?id=21689
Moved to GitHub: dmd#19799 →

Comments

Comment #0 by default_357-line — 2020-10-08T10:52:06Z
Consider the following code: ``` interface I { void foo(int i); } class C : I { override void foo(int i) in (i > 0) { } } ``` If `I` was a class, the compiler would rightly inform us that "function C.foo cannot have an in contract when overridden function I.foo does not have an in contract". However, since I is an interface, this error doesn't trigger. But it should, of course, for the same reason.
Comment #1 by kroeplin.d — 2020-10-09T14:27:57Z
Worse: no semantic analysis is done for the in condition of the override: class C : I { override void foo(int i) in (something, stupid) { } }
Comment #2 by bugzilla — 2020-12-01T08:26:21Z
Changing I to a class still does not cause the error. A function body has to be provided to I.foo() to trigger the error.
Comment #3 by dlang-bot — 2020-12-01T08:34:05Z
@WalterBright created dlang/dmd pull request #12013 "fix Issue 21298 - Missing error when overriding interface method with…" fixing this issue: - fix Issue 21298 - Missing error when overriding interface method without in contract with class method with contract https://github.com/dlang/dmd/pull/12013
Comment #4 by bugzilla — 2020-12-01T09:08:58Z
I'm not convinced this should be an error. An interface doesn't implement a function. The class providing the function isn't overriding the interface, it is implementing it.
Comment #5 by dfj1esp02 — 2021-03-09T11:05:50Z
The error is that the contract of the subtype is stricter than the contract of the supertype.
Comment #6 by robert.schadek — 2024-12-13T19:11:57Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19799 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB