Debug help - opDispatch - unknown member function
monkyyy
crazymonkyyy at gmail.com
Thu Sep 11 16:48:51 UTC 2025
On Tuesday, 9 September 2025 at 20:56:19 UTC, Steven
Schveighoffer wrote:
> On Tuesday, 9 September 2025 at 20:08:06 UTC, monkyyy wrote:
>> On Tuesday, 9 September 2025 at 19:17:11 UTC, Steven
>> Schveighoffer wrote:
>>>
>>> In short `opDispatch` only is valid if it compiles. If it
>>> doesn't compile, it's as if it doesn't exist.
>>
>> Yours still thinking declaratively, that cant be true. The
>> best description of its behavior is that it discards errors.
>>
>> ```d
>> import std;
>> enum counter=cast(immutable(void)*)[0].ptr;
>> auto getcount()=>(*(cast(int*)counter));
>> auto count()=>(*(cast(int*)counter))++;
>>
>> struct foo{
>> void opDispatch(string s)(){
>> enum _=count();
>> static assert(0);
>> }
>> }
>> void bar(foo){}
>> void foobar(foo){}
>> unittest{
>> foo().bar;
>> foo().foobar;
>> getcount.writeln;//2
>> }
>> ```
>
> This calls the UFCS versions, because the `opDispatch` version
> does not compile.
>
> The other thing is just a bug.
>
> -Steve
```d
import std;
struct foo{
void opDispatch(string s)(){
pragma(msg,"hi");
static assert(0);
}
}
void bar(foo){}
unittest{
foo().bar;//prints hi
}
```
Even if you were egregious bigoted to some features out of some
kind of spec purity belief; its demonstrable with entirely in
spec behavior
More information about the Digitalmars-d-learn
mailing list