[Issue 10999] Limited type matching

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 10 09:02:06 PDT 2013


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



--- Comment #4 from bearophile_hugs at eml.cc 2013-09-10 09:01:58 PDT ---
(In reply to comment #3)

> Reinterpreting short as ushort has nothing to do with type safety - you cannot
> corrupt anything,

"Type safety" is not the same as "memory safety". ushort and short have two
different ranges, so Ada language (and functional languages as Haskell, etc)
refuse the conversion between them. I don't like the introduction of more
implicit type conversions.

The D type system tells apart the two types:


import std.stdio;
void bar(ushort[2]) { "A".writeln; }
void bar(short[2]) { "B".writeln; }
void main() {
    ushort[2] a;
    short[2] b;
    bar(a);
    bar(b);
}


So if you write only the first bar, and you call it with an ushort[2], with
your proposal this compiles. If later you add the second bar, now the second
bar gets called. This is also what happens with single ushort and short value
arguments, but generally it's not a clean design you want to expand to arrays
too.

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


More information about the Digitalmars-d-bugs mailing list