Improve match types and compilation errors

I believe there used to be a post for this but I can’t find it. Sorry if it’s a duplicate.

It was suggested before that there should be a way to abort compilation with a custom message (much like what you can do from inline functions or macros) for match types. The reasoning is pretty simple, when a match-type fails to reduce, the compiler error message is 99/100 times unreadable and unusable for users (it’s somewhat usable while you are developing the match-type function).
The result of this is that I can never use match types for absolutely anything, because I like pretty error messages. I end up rewriting the nice and short match-type into a the traditional implicit/given approach for reduction, which takes 10x more code and looks unmaintainable.

So given that the compilation is going to be aborted anyway, can we at least control the error message? Otherwise I don’t see why you’d ever use match-types, the errors are just too unhelpful.

6 Likes

Prior discussion: https://github.com/lampepfl/dotty/pull/7951

1 Like