"potentially malformed `opDispatch`"

Ali Çehreli acehreli at yahoo.com
Mon Sep 27 19:33:19 UTC 2021


We talked about template instantiation problems hiding valuable 
information before. Here is one:

struct S {
   auto opDispatch(string symbol)() {
     static assert(symbol == "foo", "Invalid symbol.");
   }
}

void main() {
   S().bar;
}

Error: no property `bar` for type `deneme.S`
        potentially malformed `opDispatch`. Use an explicit 
instantiation to get a better error message

opDispatch fails to compile because of my 'static assert' but my message 
"Invalid symbol." is lost. Granted, the compiler recommends me to do the 
following:

   S().opDispatch!"bar";  // Ok, now I get my error message

1) Can't we display my message in the first place?

2) If we can't, can the compiler itself instantiate explicitly to show 
the error message?

3) If not even that, can we really expect a newcomer to figure out what 
to do? At least we should apologize and provide the expression for the 
programmer to try again with. :)

Ali


More information about the Digitalmars-d mailing list