www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14769] New: Cannot instantiate templates for locally defined

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

          Issue ID: 14769
           Summary: Cannot instantiate templates for locally defined
                    struct when constructor is present
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: Sigurdhsson gmail.com

The following fails to compile, with the error "Error: template std.conv.toImpl
cannot deduce function from argument types !(S2)(string)" (i.e. S1 works fine,
but S2 doesn't):

-----
import std.conv;

unittest {
  struct S1 { public string a; }
  struct S2 { public string a; this(string s) { a = s; } }
  S1 s1 = to!S1("");
  S2 s2 = to!S2(""); // <- ERROR
}
-----

Moving the struct definitions out of the unittest block also works fine:

-----
import std.conv;

struct S1 { public string a; }
struct S2 { public string a; this(string s) { a = s; } }

unittest {
  S1 s1 = to!S1("");
  S2 s2 = to!S2("");
}
-----

This is using DMD v2.067.

--
Jul 03 2015