Bug 11456 – works with -allinst but not without

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-06T14:03:53Z
Last change time
2020-07-04T17:13:10Z
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2013-11-06T14:03:53Z
Andrei reports: This works with -allinst but not without: import std.typecons; interface IDrawable { void drawLine(int x1, int y1, int x2, int y2); } class ImageDraw // note: it does not inherit IDrawable. { void drawLine(int x1, int y1, int x2, int y2) { } } /** Draw a rectangle outline. */ void drawRect(IDrawable draw) { draw.drawLine( 0, 0, 100, 0); draw.drawLine(100, 0, 100, 100); draw.drawLine( 0, 100, 100, 100); draw.drawLine( 0, 0, 0, 100); } void main() { auto imageDraw = new ImageDraw(); //drawRect(imageDraw); // error: can't call this, ImageDraw is not an IDrawable. // perform a structural cast. IDrawable i = wrap!IDrawable(imageDraw); drawRect(i); // and now imageDraw can act as an IDrawable. }
Comment #1 by andrej.mitrovich — 2013-11-06T14:09:49Z
Is this OSX-only?
Comment #2 by b2.temp — 2020-07-04T17:13:10Z
works since 2.065 w/o -allinst