-
-
Notifications
You must be signed in to change notification settings - Fork 746
Better std.algorithm.comparison.clamp error messages #8717
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
Conversation
|
Thanks for your pull request, @burner! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#8717" |
changelog/clamp_assert_message.dd
Outdated
| @@ -0,0 +1,8 @@ | |||
| Better static assert messages for `std.algorithm.comparion.clamp` | |||
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.
| Better static assert messages for `std.algorithm.comparion.clamp` | |
| Better static assert messages for `std.algorithm.comparison.clamp` |
changelog/clamp_assert_message.dd
Outdated
| @@ -0,0 +1,8 @@ | |||
| Better static assert messages for `std.algorithm.comparion.clamp` | |||
|
|
|||
| Up until now `clamp` used a template constraint to check if the passed types | |||
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.
| Up until now `clamp` used a template constraint to check if the passed types | |
| Up until now, `clamp` used a template constraint to check if the passed types |
changelog/clamp_assert_message.dd
Outdated
| Better static assert messages for `std.algorithm.comparion.clamp` | ||
|
|
||
| Up until now `clamp` used a template constraint to check if the passed types | ||
| could be used. If it were not, it was very tedious to figure out why. |
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.
| could be used. If it were not, it was very tedious to figure out why. | |
| could be used. If they were not, it was very tedious to figure out why. |
changelog/clamp_assert_message.dd
Outdated
| Up until now `clamp` used a template constraint to check if the passed types | ||
| could be used. If it were not, it was very tedious to figure out why. | ||
|
|
||
| As the template constraint is not used to overload the symbol template |
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.
| As the template constraint is not used to overload the symbol template | |
| As the template constraint is not used for overload resolution |
changelog/clamp_assert_message.dd
Outdated
| could be used. If it were not, it was very tedious to figure out why. | ||
|
|
||
| As the template constraint is not used to overload the symbol template | ||
| function, the constrains are move into static asserts with expressive error |
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.
| function, the constrains are move into static asserts with expressive error | |
| the constraints are moved into static asserts with expressive error |
| // cannot use : | ||
| // `if (is(typeof(val.lessThan(lower) ? lower : val.greaterThan(upper) ? upper : val) : T1)) | ||
| // because of https://issues.dlang.org/show_bug.cgi?id=16235. | ||
| // Once that is fixed, we can simply use the ternary in both the template constraint |
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.
This comment is not accurate anymore if the constraint is removed.
std/algorithm/comparison.d
Outdated
| ? lower | ||
| : val.greaterThan(upper) | ||
| ? upper | ||
| : val))); |
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.
I am confused as to why this assert is used given that no error message is provided.
94e31ff to
258e7ff
Compare
|
@RazvanN7 awesome review thank you, arguable better than the PR itself. |
RazvanN7
left a comment
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.
Thanks. A few nits and we are good to go.
| // `if (is(typeof(val.lessThan(lower) ? lower : val.greaterThan(upper) ? upper : val) : T1)) | ||
| // because of https://issues.dlang.org/show_bug.cgi?id=16235. | ||
| // Once that is fixed, we can simply use the ternary in both the template constraint | ||
| // and the template body |
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.
Please keep this comment. Once the bug is fixed, the body of the function (lines 590-594) can be replaced by a simple ternary.
std/algorithm/comparison.d
Outdated
| in | ||
| { | ||
| static assert(is(T2 : T1), "T2 of type '", T2.stringof | ||
| , "' must be implicitly convertable to type of T1 '" |
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.
| , "' must be implicitly convertable to type of T1 '" | |
| , "' must be implicitly convertible to type of T1 '" |
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.
std/algorithm/comparison.d
Outdated
| , "' must be implicitly convertable to type of T1 '" | ||
| , T1.stringof, "'"); | ||
| static assert(is(T3 : T1), "T3 of type '", T3.stringof | ||
| , "' must be implicitly convertable to type of T1 '" |
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.
| , "' must be implicitly convertable to type of T1 '" | |
| , "' must be implicitly convertible to type of T1 '" |
258e7ff to
d8c627e
Compare
|
@RazvanN7 thank you |
No description provided.