fix 11027: std.bitmanip.peek does not work with ranges with slicing#11029
Open
jmdavis wants to merge 1 commit into
Open
fix 11027: std.bitmanip.peek does not work with ranges with slicing#11029jmdavis wants to merge 1 commit into
jmdavis wants to merge 1 commit into
Conversation
Contributor
|
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.
|
2a37721 to
5809503
Compare
thewilsonator
approved these changes
Jun 8, 2026
…licing Okay. The basic issue here is that peek assumes that you can slice a range of ubyte and assign it to a static array of ubyte, which can't be done. And actually, since the code that checks for slicing has never worked, we can upgrade the template constraint to require a random access range in the case where slicing is required. Forward ranges with slicing _are_ valid per the range API, but they're nonsensical, because if you can implement slicing, you can implement indexing (they both take indices; it's just that one returns the same range type containing multiple elements whereas the other returns a single element). So, this fixes it so that the overload of peek that doesn't take an index works properly with ranges that have slicing, and the overload which takes an index now works with ranges (it always required slicing and didn't compile with any range that could satisfy the template constraint). I also beefed up the tests for read a bit by including some tests for them with the fix, since they can just use the same test ranges types. read was fixed for this issue previously, but the unittest block associated with its fix only tested one range type, so this is a bit more robust. Either way, I didn't touch any existing tests. write has essentially the same issue, but I'll create a PR for that after this has been merged (since they're separate bug reports).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Okay. The basic issue here is that peek assumes that you can slice a range of ubyte and assign it to a static array of ubyte, which can't be done. And actually, since the code that checks for slicing has never worked, we can upgrade the template constraint to require a random access range in the case where slicing is required. Forward ranges with slicing are valid per the range API, but they're nonsensical, because if you can implement slicing, you can implement indexing (they both take indices; it's just that one returns the same range type containing multiple elements whereas the other returns a single element).
So, this fixes it so that the overload of peek that doesn't take an index works properly with ranges that have slicing, and the overload which takes an index now works with ranges (it always required slicing and didn't compile with any range that could satisfy the template constraint).
I also beefed up the tests for read a bit by including some tests for them with the fix, since they can just use the same test ranges types. read was fixed for this issue previously, but the unittest block associated with its fix only tested one range type, so this is a bit more robust. Either way, I didn't touch any existing tests.
write has essentially the same issue, but I'll create a PR for that after this has been merged (since they're separate bug reports).