You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this code should be disallowed:
void main() {
int[char] aa1;
int[dchar] aa2;
auto r1 = aa1[0];
auto r2 = aa2[0];
}
dmd 2.065alpha compiles it with no errors, and gives at run-time:
core.exception.RangeError@temp(4): Range violation
The text was updated successfully, but these errors were encountered:
This is not as important as other changes I have proposed elsewhere.
(In reply to comment #1)
> Why? 0 implicitly converts to both char and dchar.
Because int and char are two different types. It makes code less clear, and in D there is a simple syntax to express that:
auto r1 = aa1['\0'];
auto r2 = aa2['\0'];
There is no ambiguity here, '\0' is clearly a char for the person that reads the code. Using 0 instead of '\0' seems a weakly typing archaism coming from C.
There is no ambiguity anyway. Asking for int not to convert to char is not new, and I vaguely recall it was rejected on the grounds that char x = 'a'+7; should work. I don't if there is an existing report for that.
bearophile_hugs reported this on 2013-12-12T10:11:20Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=11733
CC List
Description
I think this code should be disallowed: void main() { int[char] aa1; int[dchar] aa2; auto r1 = aa1[0]; auto r2 = aa2[0]; } dmd 2.065alpha compiles it with no errors, and gives at run-time: core.exception.RangeError@temp(4): Range violationThe text was updated successfully, but these errors were encountered: