www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - opDispatch swallowing errors really sucks

reply Adam D. Ruppe <destructionator gmail.com> writes:
class A {
     void opDispatch(string s)() {
         static assert(0);
     }
}

void main() {
     A a = new A;
     a.test();
}

$ test.d(9): Error: no property test for type test.A


Did you typo it? Is it proxying a function call with wrong 
arguments? Who knows. Here's my proposal: if opDispatch is 
considered, its errors get printed. If you don't want that spam, 
use a template constraint to remove it from consideration 
entirely.
Jan 10 2020
next sibling parent Sebastiaan Koppe <mail skoppe.eu> writes:
On Friday, 10 January 2020 at 14:58:47 UTC, Adam D. Ruppe wrote:
 Did you typo it? Is it proxying a function call with wrong 
 arguments? Who knows. Here's my proposal: if opDispatch is 
 considered, its errors get printed. If you don't want that 
 spam, use a template constraint to remove it from consideration 
 entirely.
Yeah, that one is terrible. I bumped into it myself when I wanted to give the end-user a nice error message at compile time, instead what he got was a cryptic no property error.
Jan 10 2020
prev sibling parent Ernesto Castellotti <erny.castell gmail.com> writes:
On Friday, 10 January 2020 at 14:58:47 UTC, Adam D. Ruppe wrote:
 class A {
     void opDispatch(string s)() {
         static assert(0);
     }
 }

 void main() {
     A a = new A;
     a.test();
 }

 $ test.d(9): Error: no property test for type test.A


 Did you typo it? Is it proxying a function call with wrong 
 arguments? Who knows. Here's my proposal: if opDispatch is 
 considered, its errors get printed. If you don't want that 
 spam, use a template constraint to remove it from consideration 
 entirely.
I think it happens because of issue https://issues.dlang.org/show_bug.cgi?id=14145
Jan 12 2020