www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19417] New: Separate compilation changes result of

https://issues.dlang.org/show_bug.cgi?id=19417

          Issue ID: 19417
           Summary: Separate compilation changes result of
                    __traits(compiles)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

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

--
Nov 20 2018