[Issue 11708] New: Too much weak typing of std.typecons.Typedef

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 7 07:40:55 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11708

           Summary: Too much weak typing of std.typecons.Typedef
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-12-07 07:40:53 PST ---
This code compiles and runs with no errors with dmd 2.065alpha:

void main() {
    import std.typecons: Typedef;
    alias T = Typedef!int;
    T x;
    x = 10;
    int y = 10;
    x = y;
    T[5] arr;
    arr[0] = 10;
}


The point of using Typedef is to define a strong type, so I think assigning to
it with the original type should not be allowed.

And indeed the now deprecated typedef didn't allow it:


void main() {
    typedef int T;
    int y = 10;
    T x;
    x = y; // line 5, error.
}


temp.d(5): Error: cannot implicitly convert expression (y) of type int to T

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


More information about the Digitalmars-d-bugs mailing list