June 23, 2013 [Issue 10455] New: Print range computed by expression range analysis in error messages | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=10455 Summary: Print range computed by expression range analysis in error messages Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: diagnostic Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@eml.cc 2013-06-23 13:11:24 PDT --- A low-priority enhancement request. For this code: void main() { ubyte x; ubyte y = x << 1; } The range analysis determines that it's conceivable to the result of that expression to not fit in y, so the D compiler 2.064alpha gives: temp.d(3): Error: cannot implicitly convert expression (cast(int)x << 1) of type int to ubyte To help the programmer understand faster the mistake in his/her code when expressions become more complex I think it's also useful to print the range resulting from the analysis, like: temp.d(3): Error: cannot implicitly convert expression (cast(int)x << 1) in interval [0 ... 510] of type int to ubyte It uses 3 dots because it's an interval that includes the right end. Otherwise if you print an interval open on the right in a case like this you have to print a ulong.max+1 value: void main() { ulong x; int y = x; } One downside: those error messages become a little longer (and a bit more noisy). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 23, 2013 [Issue 10455] Print range computed by expression range analysis in error messages | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=10455 --- Comment #1 from bearophile_hugs@eml.cc 2013-06-23 14:08:52 PDT --- > temp.d(3): Error: cannot implicitly convert expression (cast(int)x << 1) in > interval [0 ... 510] of type int to ubyte Jonathan M Davis suggests to use a more mathematical syntax to denote an interval closed on the right, like: temp.d(3): Error: cannot implicitly convert expression (cast(int)x << 1) in interval [0, 510] of type int to ubyte -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation