Skip to content

Conversation

@burner
Copy link
Member

@burner burner commented Mar 14, 2023

No description provided.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @burner!

Bugzilla references

Your 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 locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#8717"

@@ -0,0 +1,8 @@
Better static assert messages for `std.algorithm.comparion.clamp`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Better static assert messages for `std.algorithm.comparion.clamp`
Better static assert messages for `std.algorithm.comparison.clamp`

@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As the template constraint is not used to overload the symbol template
As the template constraint is not used for overload resolution

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

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.

? lower
: val.greaterThan(upper)
? upper
: val)));
Copy link
Collaborator

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.

@burner burner force-pushed the clamp_static_assert_message branch from 94e31ff to 258e7ff Compare March 15, 2023 10:24
@burner
Copy link
Member Author

burner commented Mar 15, 2023

@RazvanN7 awesome review thank you, arguable better than the PR itself.

Copy link
Collaborator

@RazvanN7 RazvanN7 left a 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
Copy link
Collaborator

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.

in
{
static assert(is(T2 : T1), "T2 of type '", T2.stringof
, "' must be implicitly convertable to type of T1 '"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
, "' must be implicitly convertable to type of T1 '"
, "' must be implicitly convertible to type of T1 '"

Copy link
Collaborator

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 '"
, T1.stringof, "'");
static assert(is(T3 : T1), "T3 of type '", T3.stringof
, "' must be implicitly convertable to type of T1 '"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
, "' must be implicitly convertable to type of T1 '"
, "' must be implicitly convertible to type of T1 '"

@burner burner force-pushed the clamp_static_assert_message branch from 258e7ff to d8c627e Compare March 15, 2023 15:53
@RazvanN7 RazvanN7 merged commit 91308f2 into dlang:master Mar 16, 2023
@burner
Copy link
Member Author

burner commented Mar 17, 2023

@RazvanN7 thank you

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 this pull request may close these issues.

3 participants