[Issue 15215] New: Erroneous error messages in to!IntegralType conversions
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Oct 17 04:09:42 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=15215
Issue ID: 15215
Summary: Erroneous error messages in to!IntegralType
conversions
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: samjnaa at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list