Bug 9147 – Implicit conversion to struct with alias this does not work

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-13T03:49:00Z
Last change time
2013-11-28T15:30:45Z
Assigned to
nobody
Creator
simen.kjaras

Comments

Comment #0 by simen.kjaras — 2012-12-13T03:49:44Z
struct bbyte { byte b; alias b this; } void bar(bbyte b) {} bbyte baz() { byte b; return b; // cannot implicitly convert expression (b) of type byte to bbyte } void main() { byte b; bar(b); // function bar (bbyte b) is not callable using argument types (byte) } The above code fails on the marked lines as it's trying to convert the byte to a bbyte. Ref discussion: http://forum.dlang.org/thread/[email protected]?page=3#post-mailman.2632.1355345407.5162.digitalmars-d:40puremagic.com
Comment #1 by yebblies — 2013-01-13T20:54:18Z
This is not a bug, it's working as intended. D does not support implicit construction like this.
Comment #2 by verylonglogin.reg — 2013-11-09T02:12:25Z
Also note currently `alias this` has nothing to do with conversion *to* containing type.
Comment #3 by simen.kjaras — 2013-11-28T14:26:18Z
Yeah, this one can never work.