[Issue 1834] New: typedeffed primitaves can't lose their constancy

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 14 00:53:25 PST 2008


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

           Summary: typedeffed primitaves can't lose their constancy
           Product: D
           Version: 2.010
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: caron800 at googlemail.com


Just try compiling this:

void main()
{
    string s = "hello world";
    char c = s[0]; // OK

    typedef char mychar;
    alias invariant(mychar)[] mystring;

    mystring t = cast(mystring)("hello world");
    mychar d = t[0]; // Not OK
}

The way I see it, either both of the lines I've commented should compile, or
both should fail to compile. But the second one (mychar d = t[0]) causes the
following error:

cannot implicitly convert expression (t[0u]) of type invariant(mychar) to
mychar

So ... you can implicitly convert invariant(char) to char, but you can't
convert invariant(mychar) to mychar - even though the latter is just a typedef
of the former. This makes it impossible to define a "new kind of char". (Or any
primitive type). 

I understand that /in general/ you don't want invariant(T) to implicitly cast
to T, but typedefs of primitive types? That's going too far. Ideally you want
to say "if T does not contain any pointers then const(T) and invariant(T) may
implicitly cast to T".

This bug is preventing development on one of my projects.


-- 



More information about the Digitalmars-d-bugs mailing list