← Back to index
|
Original Bugzilla link
Bug 20158 – Erroneous incompatible types error for classes and interfaces when the class is not directly convertible to the interface but is convertible to a parent of the interface
Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-08-23T21:15:02Z
Last change time
2024-12-13T19:05:12Z
Assigned to
No Owner
Creator
Nathan S.
Moved to GitHub: dmd#19614 →
Comments
Comment #0
by n8sh.secondary — 2019-08-23T21:15:02Z
Demonstration:
https://run.dlang.io/is/tlyu7Z
--- interface I { void foo(); } interface J : I { void bar(); } class C1 : I { override void foo() {} } class C2 : J { override void foo() {}; override void bar() {}; } I newI() { return new C1(); } J newJ() { return new C2(); } C1 newC1() { return new C1(); } void main(string[] args) { const c = args.length > 1; I blah; // Compiles: if (c) blah = newJ(); else blah = newC1(); // Fails to compile: blah = c ? newJ() : newC1(); // Error: incompatible types for (newJ()) : (newC1()): J and C1 // Fails to compile: blah = () { if (c) return newJ(); else return newC1(); // Error: mismatched function return type inference of C1 and J }(); // P.S. // When the class directly implements the interface there is no problem. auto _ = c ? newI() : newC1(); } ---
Comment #1
by robert.schadek — 2024-12-13T19:05:12Z
THIS ISSUE HAS BEEN MOVED TO GITHUB
https://github.com/dlang/dmd/issues/19614
DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB