[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 17:47:51 UTC 2023


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

--- Comment #3 from m.bierlee at lostmoment.com ---
(In reply to RazvanN from comment #1)
> 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

Thanks for your clarification. Perhaps this could be clarified in the
documentation then?

Could you provide an example regarding assigning the function and instance to a
delegate? Whatever I try myself doesn't work, the compile keeps saying "Error:
`this` for `theMethod` needs to be type [...]".

--


More information about the Digitalmars-d-bugs mailing list