Skip to content

Prevent arbitrary objects from conforming to RNG. #36969

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

Merged
merged 1 commit into from
Apr 20, 2021

Conversation

stephentyrone
Copy link
Contributor

@stephentyrone stephentyrone commented Apr 20, 2021

Me, sobbing: "Look, you can't just point at an empty struct and call it a RandomNumberGenerator."
Swift 5.4, pointing at absolutely anything: "RNG."

This is technically a source-breaking change. However, any RNG that depended on this behavior to conform to the protocol was necessarily already broken; it could never have worked correctly. So we're simply moving the crash from runtime to compile time, making it easier for users to find and do something about it.

Fixes rdar://76660011

Me, sobbing: "Look, you can't just point at an empty struct and call it a RandomNumberGenerator."
Swift 5.4, pointing at anything: "RNG."
@stephentyrone
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - c2249b3

Copy link
Contributor

@Azoy Azoy left a comment

Choose a reason for hiding this comment

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

Me reviewing: "Look, you can't just add a default impl with fatalError and expect the compiler to complain that the user hasn't conformed to RNG."
Steve: "Unavailable."

Yep, this looks right to me!

@stephentyrone
Copy link
Contributor Author

@swift-ci please test linux

@stephentyrone stephentyrone merged commit 8736683 into swiftlang:main Apr 20, 2021
@stephentyrone stephentyrone deleted the rng-go-brrrr branch April 20, 2021 20:39
stephentyrone added a commit to stephentyrone/swift that referenced this pull request Apr 21, 2021
Me, sobbing: "Look, you can't just point at an empty struct and call it a RandomNumberGenerator."
Swift 5.4, pointing at anything: "RNG."
stephentyrone added a commit that referenced this pull request Apr 22, 2021
Me, sobbing: "Look, you can't just point at an empty struct and call it a RandomNumberGenerator."
Swift 5.4, pointing at anything: "RNG."
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