Bug 17921 – allow to use `alias function this` to be used for implicit conversions

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-10-20T21:47:01Z
Last change time
2024-12-13T18:54:55Z
Assigned to
No Owner
Creator
Martin Nowak
Moved to GitHub: dmd#19328 →

Comments

Comment #0 by code — 2017-10-20T21:47:01Z
cat > enh.d << CODE struct IPv4Addr { alias IPAddr this; // alias type constructor for implicit conversion } // either IPv4 or IPv6 struct IPAddr { this(IPv4Addr) {} } void func(IPAddr) { } unittest { func(IPv4Addr()); } CODE dmd -c -unittest enh.d ---- enh.d(3): Error: IPAddr is not a member of IPv4Addr ---- At the moment alias this for implicit conversions needs a dummy member method. When you already have `IPAddr(IPv4Addr.init)` it's somewhat annoying to add `IPv4Addr.init.toIPAddr` to the public API, only to support implicit conversions. Now there are 2 ways to do the same thing, sth. that's usually to be avoided in API design. Alias-thising a free function or type would be resolved like `var.func` calls, and according to the current alias this rules. Obviously this should be coordinated with the multiple alias this work.
Comment #1 by robert.schadek — 2024-12-13T18:54:55Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19328 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB