Skip to content

[4.2] Make upperBound != 0 a precondition for RNG.next(upperBound:) (#17627) #17631

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

stephentyrone
Copy link
Contributor

@stephentyrone stephentyrone commented Jun 29, 2018

The function's definition is "Returns a random value that is less than the given upper bound," which cannot possibly be satisfied with upperBound == 0; previously the function returned zero, which was a bug.

Resolves SR-8143 and rdar://problem/41735302.

Explanation: Without this change, RNG.next(upperBound: bound) can return a value that does not satisfy the invariant bound < upperBound.
Scope: Minor, but we want to be able to guarantee this invariant holds.
Issue #: https://bugs.swift.org/browse/SR-8143
Risk: Very low.
Testing: Standard regression tests. Random is a new feature, and this only fixes an error case.
Reviewer: @lorentey

…ang#17627)

The function's definition is "Returns a random value that is less than the given upper bound," which cannot possibly be satisfied with upperBound == 0; previously the function returned zero, which was a bug.
@stephentyrone
Copy link
Contributor Author

@swift-ci Please test

@stephentyrone
Copy link
Contributor Author

@swift-ci nominate

@airspeedswift airspeedswift merged commit faf89e6 into swiftlang:swift-4.2-branch Jul 2, 2018
@stephentyrone stephentyrone deleted the random-upperbound-zero-4.2 branch July 2, 2018 19:52
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.

2 participants