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
Static verification of std.getopt arguments with more helpful error messages #3859
Conversation
|
return result; | ||
} | ||
|
||
static unittest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding static
in front of unittest
doesn't do anything
Perhaps one way to avoid needing to use To prevent copy-pasta between the template that verifies the arguments and the template that emits the error messages, what you could do perhaps is something like this:
|
P.S. Of course, you'll have to refactor the checking code to use recursive templates instead, then you can propagate errors up the template instantiation chain like this:
|
Thanks for the last comments, using a template was the solution. It even works without recursion. The diagnotsic is now emitted correctly (initially the problem was that pragma is an optional compiler feature) and the error line is not lost. The last thing mays be a more accurate checking of the receivers type (bool*, pointer to numeric, pointer to string, etc.). Currently the validator accepts invalid pointers or invalid delegates. The Q. is is it worth ?, since I myself recognize that the usefulness of this PR is low. I mean that it can help someone who already knows std.getopt a bit to detect a small error but someone who starts from scratch will still have to read the manual to get that a lot of things are allowed in the variadic options. |
I think what you currently have is useful as-is. Adding more precise checks is just icing on top of that. At some point, if the diagnostics function becomes equally or more complex than On another note, I wonder if it's possible to massage |
on invalid pattern: - outputs a message that gives a hint about the wrong type - includes the index of the wrong option the message doesn't hide the error origin becasue pragma(msg) is used instead or assert(0)
#3859 squashed and ready for decision |
LGTM. Thanks! |
Auto-merge toggled on |
Static verification of std.getopt arguments with more helpful error messages
Dont esitate to ping me if you find a problem in my static checking. Theorically it sould not happen since each unittest that already exist also dependent on this... We'll see this in 2.071... |
This pull request introduced a regression: |
No it's not the static checker (I'm the reporter, b2.temp, BTW). On my local repo which is at master, even if deactivate the static checker a char is not accepted anymore. |
I'm not pointing fingers or stating which part of this pull request introduced a regression, but by the simple test of "did it compile before this pull request? and after?", this pull request introduced the regression. |
Yes it used to compile. Coedit symbol list was compiled and released two times with 2.070, and it contains an option specifier made of char: https://github.com/BBasile/Coedit/blob/master/cesyms/cesyms.d#L40 |
You can reproduce my result with these Digger settings:
And my result:
|
I don't understand what you are trying to prove with that screenshot. Are you really actually trying to prove that the bisection result is wrong? Like I said, the problem might not be in your code - it could be due to a change in DMD, or a latent DMD bug. |
No I'm trying to demonstrate that this PR is not the responsible for the bug. While I can update the validator to handle chars (already done locally), I can't do anything if it's a dmd bug. So what I suggest is to add the unittest like in the screen shot and to deactivate the static checker so that someone can work on the real bug. When it'll get fixed I'll update the validator. |
Um, looking at this patch, how can that possibly be correct? Your code never checks for chars, only strings ( |
Was getOpt supposed to accept a char initially ? The doc doesn't mention it. All this conversation may be a useless drama. 😆 |
If it broke your code, it's very likely it broke someone else's. |
OK: #4187 |
No, I can post a fix very quickly. After verification the bisection is right. the unittest failed for another reason. |
related issues:
In short, this PR proposes a way to statically check the variadic options in getOpt (it detects invalid pattern such as two consecutive recipients). The problem is that it uses
pragma(msg)
to output the diagnostic, butpragma(msg)
is never used in phobos (so far).The constraint works fine but maybe you'll be able to find and suggest a better way to output the diagnostic without losing the line of the error (for example with
assert(0)
the error origin is lost).