Bug 6197 – std.traits.isImplicitlyConvertible returns some wrong results.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-06-23T04:01:00Z
Last change time
2012-06-14T02:20:55Z
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2011-06-23T04:01:22Z
pragma(msg, implicitlyConverts!(const(uint), ubyte)); should print 'false', but 'true'. Cause of this bug: Current implementation is here: template isImplicitlyConvertible(From, To) { enum bool isImplicitlyConvertible = is(typeof({ void fun(To) {} From v; fun(f); }())); } When From=const(uint) and To=ubyte, it is rewites as enum bool isImplicitlyConvertible = is(typeof({ void fun(ubyte) {} const(uint) v; fun(f); }())); and function argument v is *optimized* to its initial value 0u and matches to parameter type ubyte by literal conversion. How to fix: The variables its initializers are not visible does not cause optimization. So rewrite as: enum bool isImplicitlyConvertible = is(typeof({ void fun(ref From v){ void gun(To) {} gun(v); } }()));
Comment #1 by k.hara.pg — 2011-06-23T04:06:35Z
(In reply to comment #0) > pragma(msg, implicitlyConverts!(const(uint), ubyte)); Sorry, this is miss type. Following is correct. pragma(msg, isImplicitlyConvertible!(const(uint), ubyte));
Comment #2 by lovelydear — 2012-04-24T11:36:13Z
With 2.059 Win32 PS E:\DigitalMars\dmd2\samples> dmd -c bug.d false
Comment #3 by k.hara.pg — 2012-06-14T02:20:55Z
Already fixed in 2.060head.