www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1834] New: typedeffed primitaves can't lose their constancy

reply d-bugmail puremagic.com writes:

           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 digitalmars.com
        ReportedBy: caron800 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

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.

Feb 14 2008
parent d-bugmail puremagic.com writes:

bugzilla digitalmars.com changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME

------- Comment #1 from bugzilla digitalmars.com  2008-03-04 01:50 -------
Works in dmd 2.011 (no errors for either case).

Mar 03 2008