Bug 8597 – UFCS fails when used with a pointer to enum and implicit dereferencing

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-28T23:03:03Z
Last change time
2022-09-08T08:56:39Z
Assigned to
No Owner
Creator
Tommi

Comments

Comment #0 by tommitissari — 2012-08-28T23:03:03Z
module main; enum MyEnum { first, second, third } MyEnum next(MyEnum myenum) { return cast(MyEnum) (myenum + 1); } void main() { auto myenum = MyEnum.second; auto ptrEnum = &myenum; auto maxEnum = ptrEnum.max; // #0: OK auto nextExplicit = (*ptrEnum).next(); // #1: OK auto nextImplicit = ptrEnum.next(); // #2 } #2: Error: function main.next (MyEnum myenum) is not callable using argument types (MyEnum*) #2: Error: cannot implicitly convert expression (ptrEnum) of type MyEnum* to MyEnum
Comment #1 by andrej.mitrovich — 2013-01-25T16:22:11Z
I think this is deliberate and it's unrelated to enums: int ufcs(int i) { return 0; } void main() { auto i = 0; auto ptrInt = &i; auto a = ptrInt.ufcs(); // error } Same with structs. There was a similar issue opened where someone made a rationale, it was about not wanting to accidentally pass structs by value, or something like that. I'll wait for someone to give a better response.
Comment #2 by k.hara.pg — 2013-04-24T00:34:21Z
> There was a similar issue opened where someone made a rationale, it was about > not wanting to accidentally pass structs by value, or something like that. I'll > wait for someone to give a better response. Currently automatic pointer dereference is not supported in UFCS name look up. So this is an enhancement request.
Comment #3 by razvan.nitu1305 — 2022-09-08T08:56:39Z
I oppose this enhacement request because it adds additional complexity to the compiler for something that is easily worked around by using dereferenciation.