digitalmars.D.bugs - [Issue 10757] New: int incremented with double NaN doesn't give a "cannot implicitly convert expression" error
- d-bugmail puremagic.com (50/54) Aug 04 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10757
http://d.puremagic.com/issues/show_bug.cgi?id=10757 Summary: int incremented with double NaN doesn't give a "cannot implicitly convert expression" error Product: D Version: D2 Platform: x86 OS/Version: Windows Status: NEW Keywords: accepts-invalid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: bearophile_hugs eml.cc With dmd 2.064alpha this terrible program compiles with no errors nor warnings, and it runs with no asserts: void main() { double x; int y; y += x; assert(y == int.min); y += 3.5; assert(y == -2147483644); } What I'd like: that code to become a compile time error (a "cannot implicitly convert expression" error), because I think it's against the idea of strong typing. I prefer a language that doesn't silently drops floating point parts (like 0.5 here) and that catches me if I increment an integer variable by mistake by a floating point value. (Probably I will not close down this bug report, so if someone (like Walter) is against it then he should close it down. Such person should also show one or more practical situations where allowing that code gives an advantage over generating a compile-time error. I leave the burden of showing the usefulness on the shoulders of the person willing to close this issue down.) In a dynamically typed language as Python2.6 int+float or int+=float return a float, so this behavour is acceptable:nan I am aware that in D the increment at line 4 is accepted, but this is just a matter of disabling the value range tests that are so good in D, this is a different situation from adding a double to an int: void main() { int x; byte y; y += x; // line 4, OK byte z = x; // Error: cannot implicitly convert } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------x = float("nan") y = 0 y += x y
Aug 04 2013