Bug 9572 – Missed wrong implicit integral conversion

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-22T11:09:00Z
Last change time
2013-11-23T05:03:14Z
Keywords
accepts-invalid, diagnostic, pull
Assigned to
nobody
Creator
bearophile_hugs
See also
http://d.puremagic.com/issues/show_bug.cgi?id=9570

Comments

Comment #0 by bearophile_hugs — 2013-02-22T11:09:10Z
void main() { int[300] data; foreach (ubyte i, x; data) {} // Line 3, no error. ubyte j = data.length; // Line 4, Error. } DMD 2.063alpha gives: temp.d(4): Error: cannot implicitly convert expression (300u) of type uint to ubyte But line 3 should give a similar error message, because data has 300 items, so the "i" index can't represent all the possible indexes. See also issue 9570.
Comment #1 by yebblies — 2013-11-22T21:50:21Z
Comment #2 by github-bugzilla — 2013-11-23T00:31:56Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/0a8f89e122eba08e58cac218f92c639f514720c3 Fix Issue 9572 - Missed wrong implicit integral conversion https://github.com/D-Programming-Language/dmd/commit/66e6ed1955895d8423ca8348419548324e62e612 Merge pull request #2859 from yebblies/issue9572 Issue 9572 - Missed wrong implicit integral conversion
Comment #3 by bearophile_hugs — 2013-11-23T04:56:35Z
void main() { int[300] data; foreach (ubyte i, x; data) {} // Line 3, no error. ubyte j = data.length; // Line 4, Error. } Now the error messages are correct (but there is an extra newline in the middle): temp.d(3): Error: index type 'ubyte' cannot cover index range 0..300 temp.d(4): Error: cannot implicitly convert expression (300u) of type uint to ubyte
Comment #4 by yebblies — 2013-11-23T05:03:08Z
Whoops. Too much printf on the brain.
Comment #5 by yebblies — 2013-11-23T05:03:14Z