D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11456 - works with -allinst but not without
Summary: works with -allinst but not without
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-06 14:03 UTC by Walter Bright
Modified: 2020-07-04 17:13 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2013-11-06 14:03:53 UTC
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 Andrej Mitrovic 2013-11-06 14:09:49 UTC
Is this OSX-only?
Comment 2 basile-z 2020-07-04 17:13:10 UTC
works since 2.065 w/o -allinst