Bug 15215 – Erroneous error messages in to!IntegralType conversions

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-10-17T11:09:00Z
Last change time
2016-12-23T21:23:58Z
Keywords
pull
Assigned to
dlang-bugzilla
Creator
samjnaa

Comments

Comment #0 by samjnaa — 2015-10-17T11:09:42Z
Using DMD 2.068.2. Code illustrating problem: $ cat to_int_error_msg.d import std.meta, std.conv, std.stdio; void test(string num) { writeln("Testing string: ", num); foreach(Type; AliasSeq!(ubyte, ushort, uint, ulong, byte, short, int, long)) { try to!Type(num); catch (ConvException e) writefln("to!%-6s : %s", Type.stringof, e.msg); } writeln(); } void main() { foreach (num; ["2A", "-2A", "#2A"]) test(num); } Output: $ dmd -run to_int_error_msg.d Testing string: 2A to!ubyte : Unexpected 'A' when converting from type string to type ubyte to!ushort : Unexpected 'A' when converting from type string to type ushort to!uint : Unexpected 'A' when converting from type string to type uint to!ulong : Unexpected 'A' when converting from type string to type ulong to!byte : Unexpected 'A' when converting from type string to type byte to!short : Unexpected 'A' when converting from type string to type short to!int : Unexpected 'A' when converting from type string to type int to!long : Unexpected 'A' when converting from type string to type long Testing string: -2A to!ubyte : Unexpected '2' when converting from type string to type uint to!ushort : Unexpected '2' when converting from type string to type uint to!uint : Unexpected '2' when converting from type string to type uint to!ulong : Unexpected '2' when converting from type string to type ulong to!byte : Unexpected 'A' when converting from type string to type byte to!short : Unexpected 'A' when converting from type string to type short to!int : Unexpected 'A' when converting from type string to type int to!long : Unexpected 'A' when converting from type string to type long Testing string: #2A to!ubyte : Unexpected '2' when converting from type string to type uint to!ushort : Unexpected '2' when converting from type string to type uint to!uint : Unexpected '2' when converting from type string to type uint to!ulong : Unexpected '2' when converting from type string to type ulong to!byte : Unexpected '2' when converting from type string to type int to!short : Unexpected '2' when converting from type string to type int to!int : Unexpected '2' when converting from type string to type int to!long : Unexpected '2' when converting from type string to type long Observations: When input is 2A, error messages are fine. When input is -2A, error messages are fine in case of signed types. In case of unsigned types, there are two problems: 1) The message should flag the presence of "-" which is illegal in unsigned types. It instead says "2" is unexpected. 2) The target type is wrongly mentioned as uint when it is actually ubyte or ushort. When input is #2A, error messages are not fine at all. The problems are: 1) Again, "2" is flagged as unexpected instead of "#". 2) The target type is wrongly mentioned as before, but now int is displayed for byte and short too.
Comment #1 by dlang-bugzilla — 2015-10-18T01:34:22Z
Comment #2 by hsteoh — 2016-02-19T23:45:51Z
Whoa, just realized that https://issues.dlang.org/show_bug.cgi?id=15695 is a duplicate of this bug, and I submitted a fix for it without realizing that https://github.com/D-Programming-Language/phobos/pull/3728 is essentially the same fix! Anyway... since the fix has been checked in, can this be closed now?
Comment #3 by dlang-bugzilla — 2016-02-19T23:56:01Z
Yes assuming your PR is a superset of this one I guess.
Comment #4 by hsteoh — 2016-02-20T00:01:59Z
I dunno, the unittest in my PR is a bit hackish. Maybe you should rebase your PR and checkout the better unittests?
Comment #5 by hsteoh — 2016-02-20T00:02:21Z
I mean *checkin*.
Comment #6 by dlang-bugzilla — 2016-02-20T00:03:42Z
My hands are a bit full these days, sorry...
Comment #7 by schveiguy — 2016-02-20T00:33:29Z
(In reply to hsteoh from comment #4) > I dunno, the unittest in my PR is a bit hackish. Maybe you should rebase > your PR and checkout the better unittests? Maybe new PR with unit tests? Let the auto-tester do the work ;)
Comment #8 by andrei — 2016-12-23T21:19:00Z
Current output: Testing string: 2A to!ubyte : Unexpected 'A' when converting from type string to type ubyte to!ushort : Unexpected 'A' when converting from type string to type ushort to!uint : Unexpected 'A' when converting from type string to type uint to!ulong : Unexpected 'A' when converting from type string to type ulong to!byte : Unexpected 'A' when converting from type string to type byte to!short : Unexpected 'A' when converting from type string to type short to!int : Unexpected 'A' when converting from type string to type int to!long : Unexpected 'A' when converting from type string to type long Testing string: -2A to!ubyte : Unexpected '-' when converting from type string to type uint to!ushort : Unexpected '-' when converting from type string to type uint to!uint : Unexpected '-' when converting from type string to type uint to!ulong : Unexpected '-' when converting from type string to type ulong to!byte : Unexpected 'A' when converting from type string to type byte to!short : Unexpected 'A' when converting from type string to type short to!int : Unexpected 'A' when converting from type string to type int to!long : Unexpected 'A' when converting from type string to type long Testing string: #2A to!ubyte : Unexpected '#' when converting from type string to type uint to!ushort : Unexpected '#' when converting from type string to type uint to!uint : Unexpected '#' when converting from type string to type uint to!ulong : Unexpected '#' when converting from type string to type ulong to!byte : Unexpected '#' when converting from type string to type int to!short : Unexpected '#' when converting from type string to type int to!int : Unexpected '#' when converting from type string to type int to!long : Unexpected '#' when converting from type string to type long
Comment #9 by dlang-bugzilla — 2016-12-23T21:21:29Z
Please use WORKSFORME for entries that have been fixed elsewhere, so they don't appear in the changelog.
Comment #10 by andrei — 2016-12-23T21:23:58Z
(In reply to Vladimir Panteleev from comment #9) > Please use WORKSFORME for entries that have been fixed elsewhere, so they > don't appear in the changelog. Roger.