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
Revert fix for 18631. #6331
Revert fix for 18631. #6331
Conversation
The fix for 18631 broke code. Ranges cannot be marked with const or inout in generic code. The range API does not require that any functions be const or inout. In this case, with the changes, choice requires that length and opSlice be const, breaking any code that uses a range with choice that does not have a const length or opSlice (which is going to be a large percentage of ranges with those functions which aren't arrays).
Thanks for your pull request, @jmdavis! 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. |
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.
Unfortunately, I have to agree. I don't see any easy way to salvage the original fix. Perhaps a separate overload for arrays might be good enough. But I don't see how it could be solved for general ranges, where the const-ness of methods are not guaranteed.
Couldn't you have two overloads and explicitly check if length and opSlice are const, one overload requiring both and the other overload requiring not both? |
The normal solution that we've gone with is to just do nothing about Regardless, I'd rather leave a proper fix to another PR and just revert the current changes so that the broken code is no longer broken. |
Copying comment from other PR: Since it's pretty accepted that you can slice an object and get a range from it, Another way to fix this may be (not a full implementation, needs some tweaking): auto ref choice(R)(auto ref R r) if (!isRandomAccessRange!R && isRandomAccessRange!(typeof(r[])))
{
return choice(r[]);
} It should work for containers as well, such as |
The fix for 18631 broke code. Ranges cannot be marked with const or
inout in generic code. The range API does not require that any functions
be const or inout. In this case, with the changes, choice requires that
length and opSlice be const, breaking any code that uses a range with
choice that does not have a const length or opSlice (which is going to
be a large percentage of ranges with those functions which aren't
arrays).