digitalmars.D.bugs - [Issue 1834] New: typedeffed primitaves can't lose their constancy
- d-bugmail puremagic.com (37/37) Feb 14 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1834
- d-bugmail puremagic.com (9/9) Mar 03 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1834
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 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 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. --
Feb 14 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1834 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |WORKSFORME Works in dmd 2.011 (no errors for either case). --
Mar 03 2008