www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6313] New: Type deduction with const/in


           Summary: Type deduction with const/in
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc

--- Comment #0 from bearophile_hugs eml.cc 2011-07-14 04:50:53 PDT ---
A D2 program:

T[] foo(T)(const T[] x) {
    //static assert(is(U == int)); // false
    static assert(is(T == const(int)));
    return new T[1];
U[] bar(U)(const U[] y) {
    static assert(is(U == int));
    return foo(y);
void main() {

DMD 2.054 gives:
test.d(8): Error: cannot implicitly convert expression (foo(y)) of type
const(int)[] to int[]
test.d(11): Error: template instance test.bar!(int) error instantiating

This causes me problems because many of my functions have "in" arguments. When
they call each other they don't compile, as in this example (here I have used
"const" arguments just for clarity).

To solve the problem I have had to use code like this, that I don't like a lot:

Unqual![] foo(T)(const T[] x) {
    return new Unqual!T[1];
U[] bar(U)(const U[] y) {
    return foo(y);
void main() {

So, is it possible (and good) to change DMD so the type T of foo is "int"
instead of "const(int)"?

See also comments by Daniel Murphy:

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 14 2011