[Issue 23761] Trait getOverloads does not retain "this" reference when used with instance

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 7 13:47:15 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23761

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305 at gmail.com> ---
traits(getOverloads) wasn't designed to work on instances as you expect. The
spec doesn't explicitly forbid it [2], but looking at the example and the
implementation, it is implied. The compiler just needs an aggregate type as the
second parameter of traits(getOverloads), but if an expression is provided it
simply extracts the type and it returns a sequence of symbols (i.e. function
pointers). Of course, for free functions you can call the symbols, but for
member functions you need to provide a context pointer (which can be done by
using a delegate and setting the .ptr field [1]).

In this case, the compiler sees the call to the symbol and assumes that it's a
local symbol. Of course, the error message could be improved, but currently the
frontend cannot reason about the context pointer in this situation, so it's
highly likely that this will remain WONTFIX.

[1] https://dlang.org/spec/function.html
[2] https://dlang.org/spec/traits.html#getOverloads

--


More information about the Digitalmars-d-bugs mailing list