Bug 1834 – typedeffed primitaves can't lose their constancy

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-02-14T02:53:00Z
Last change time
2015-06-09T01:14:30Z
Assigned to
bugzilla
Creator
caron800

Comments

Comment #0 by caron800 — 2008-02-14T02:53:22Z
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.
Comment #1 by bugzilla — 2008-03-04T01:50:43Z
Works in dmd 2.011 (no errors for either case).