D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19417 - Separate compilation changes result of __traits(compiles)
Summary: Separate compilation changes result of __traits(compiles)
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-20 20:11 UTC by Paul Backus
Modified: 2024-12-13 19:01 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Paul Backus 2018-11-20 20:11:02 UTC
The following program prints "true" when compiled together, and "false" when compiled separately:

--- dub.json
{
    "name": "example"
}

--- source/app.d
import node;

void main()
{
    import std.stdio;
    writeln(__traits(compiles, Struct.init == Struct.init));
}

--- source/node.d
import example;

alias Node = Example!Struct;
struct Struct { Node[] nodes; }

--- source/example.d
struct Example(T)
{
    T t;

    static if (__traits(compiles, T.init == T.init)) {
        bool opEquals(Example!T rhs) { return this.t == rhs.t; }
    } else {
        @disable bool opEquals(Example!T rhs);
    }
}

---

To build and run with dub:

$ dub --quiet build --build-mode=singleFile --force && dub --quiet run                                                                                   
false
$ dub --quiet build --force && dub --quiet run                                                                                                           
true
Comment 1 dlangBugzillaToGithub 2024-12-13 19:01:23 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19511

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB