Showing a user specified error message when no overloads match

Artur Skawina via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 29 09:57:00 PDT 2014


On 07/29/14 17:45, H. S. Teoh via Digitalmars-d-learn wrote:
> You're right, opDispatch behaves like SFINAE. I've had trouble debugging
> it before, because when it works, it works very well, but when you
> accidentally make a typo, it just "disappears" -- you get an error that
> the property is missing, but the actual error inside opDispatch has been
> gagged and it's almost impossible to get at the actual error message.

D's overloaded operators are (usually) normal (templated) functions, you
can use `a.opDispatch!"blah"` instead of `a.blah` to see what's wrong.

What's really nasty is the way phobos handles `toString` - if that method
fails to compile then you get a usually not very helpful default, and no
warning that something is wrong. It's easy to break `toString` w/o noticing
anything. Figuring out later what exactly broke can be "interesting". Still
doable via the above mentioned trick, but you'll need to create a mock `sink`
etc.

artur


More information about the Digitalmars-d-learn mailing list