[Issue 2125] New: Moving a template to a separate module breaks compilation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 23 12:46:27 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2125

           Summary: Moving a template to a separate module breaks
                    compilation
           Product: D
           Version: 2.013
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: bartosz at relisoft.com


---File totype.d---
module totype;
import std.string;

template ToType (string s)
{
    alias ToTypeHelper!(s).type ToType;
}

template ToTypeHelper (string s)
{
    mixin ("alias " ~ s ~ " type;");
}
----File test.d---
import std.stdio;
import std.string;
import totype;

// Concatenate strings with a separator
string ctConcat (string [] arr, char sep)
{
    assert (arr.length != 0);
    string result = "";
    foreach (s; arr)
        result ~= s ~ sep;
    return result [0..$-1]; // remove the trailing sep
}

string Options (string [] bases)
{
        if (bases.length == 0)
                return "NoLock";
        return ctConcat (bases, '_');
}

interface A_B {}

void main ()
{
        ToType!(Options (["A","B"])) lockOptions;
}
----Output----
c:\D\Work>dmd -oftest.exe test totype
Error: identifier 'A_B' is not defined
totype.d(6): template instance totype.ToTypeHelper!(s) error instantiating
totype.d(6): Error: forward reference to 'A_B'
-------
The error disappears when the contents of totype.d is copied directly to test.d
.


-- 



More information about the Digitalmars-d-bugs mailing list