Bug 23240 – dmd compiles 'ok' class invalid to interface if class contains abstract members

Status
NEW
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-07-11T22:02:42Z
Last change time
2024-12-13T19:23:49Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Alexey
Moved to GitHub: dmd#18117 →

Comments

Comment #0 by animuspexus — 2022-07-11T22:02:42Z
following code compiles ok, but it shouldn't: interface doesn't match. this bug doesn't work if there are no abstract member in class. ```D import std.stdio; interface ClassInterface { ClassInterface setValue(string val); } class ClassPrototype : ClassInterface { string value; void setValue(string val) { value = val; } abstract void doSomething(); } class Class : ClassPrototype { override void doSomething() { writeln("321"); } } void main() { auto inst = new Class(); inst.setValue("123"); } ```
Comment #1 by animuspexus — 2022-07-11T22:12:51Z
also, the following modification to the code compiles ok and resulting program segfaults on run ``` import std.stdio; interface ClassInterface { ClassInterface setValue(string val); } class ClassPrototype : ClassInterface { string value; void setValue(string val) { value = val; } abstract void doSomething(); } class Class : ClassPrototype { override void doSomething() { writeln("321"); } } void main() { auto inst = new Class(); inst.setValue("123"); ClassInterface zzz = cast(ClassInterface) inst; assert(zzz); auto xxx = zzz.setValue("333"); } ```
Comment #2 by kinke — 2022-07-11T22:39:03Z
This is a regression. According to run.dlang.io: 2.060-2.063: onlineapp.d(12): Error: function onlineapp.ClassPrototype.setValue of type void(string val) overrides but is not covariant with onlineapp.ClassInterface.setValue of type ClassInterface(string val) 2.064-2.092: onlineapp.d(20): Error: class `onlineapp.Class` interface function `ClassInterface setValue(string val)` is not implemented Wrongly compiles since v2.093.
Comment #3 by animuspexus — 2022-07-13T02:22:55Z
looks like this bug is related to those bugs https://issues.dlang.org/show_bug.cgi?id=21321 https://issues.dlang.org/show_bug.cgi?id=21184 basically, I've simply searched by 'abstract word' and there are looks like more related bugs.
Comment #4 by robert.schadek — 2024-12-13T19:23:49Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18117 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB