Bug 8807 – Better error messages for a switch on doubles
Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-12T14:38:00Z
Last change time
2013-01-20T10:00:49Z
Keywords
diagnostic, pull
Assigned to
andrej.mitrovich
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-10-12T14:38:24Z
From the thread:
http://forum.dlang.org/thread/[email protected]
void main() {
double value = 1;
switch (value) {
case 1:
// do something
break;
default:
}
}
DMD 2.061alpha gives:
temp2.d(3): Error: 'value' is not of integral type, it is a double
temp2.d(4): Error: case must be a string or an integral constant, not 1
The error messages are not so good:
- The first error message misses the possibility of a switch on strings.
- The second error message is just wrong, because 1 is on default an integral constant.
Comment #1 by andrej.mitrovich — 2013-01-10T15:50:45Z
(In reply to comment #0)
> temp2.d(3): Error: 'value' is not of integral type, it is a double
This is solved in pull for Issue 4540.
> temp2.d(4): Error: case must be a string or an integral constant, not 1
> - The second error message is just wrong, because 1 is on default an integral
> constant.
It's not actually wrong, 1 is implicitly converted to type double. Unfortunately it doesn't print 1.0 to make it obvious.
Comment #2 by andrej.mitrovich — 2013-01-19T19:59:16Z