Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad error message when having a single handler that's supposed to match everything #81

Open
WebFreak001 opened this issue Mar 7, 2022 · 1 comment

Comments

@WebFreak001
Copy link

Example:

	int someFun(T)(T v)
	{
		static assert(!is(T == int));
		return 3;
	}

	SumType!(int, string, This[]) v;
	v.match!(all => someFun(all));

use-case is that I have a generic (de)serialization function that's supposed to work on every type of my sumtype, but it doesn't for one. The current error message says something like:

/usr/include/dlang/dmd/std/sumtype.d(1998,13): Error: static assert:  "`handlers[0]` of type `template` never matches"
/usr/include/dlang/dmd/std/sumtype.d(1590,52):        instantiated from here: `matchImpl!(SumType!(typeof(null), string, bool, long, double, This[], This[string]))`
source/workspaced/backend.d(132,15):        instantiated from here: `match!(SumType!(typeof(null), string, bool, long, double, This[], This[string]))`
source/workspaced/backend.d(149,22):        instantiated from here: `deepCopy!(SumType!(typeof(null), string, bool, long, double, This[], This[string]))`
source/workspaced/backend.d(136,40):        instantiated from here: `deepCopy!(SumType!(typeof(null), string, bool, long, double, This[], This[string])[string])`
source/workspaced/backend.d(113,30):        instantiated from here: `deepCopy!(Section)`

which is hard to debug.

I propose to add a special case for single-pattern match invocations, where it will just shove it into my custom handler without testing if it's plausible and just let compiler errors break it.

WebFreak001 added a commit to WebFreak001/sumtype that referenced this issue Mar 7, 2022
For improved error messages, fixes pbackus#81
WebFreak001 added a commit to WebFreak001/sumtype that referenced this issue Mar 7, 2022
For improved error messages, fixes pbackus#81
@pbackus
Copy link
Owner

pbackus commented Mar 7, 2022

As discussed in #82, solving this properly will require improving __traits(compiles) so that matchImpl can get access to the error messages produced when a handler fails to match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants