-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add the EXACTLY_ONCE contract to suspendCancellableContinuation
#4574
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,4 +134,15 @@ class CancellableContinuationTest : TestBase() { | |
| }) | ||
| finish(5) | ||
| } | ||
|
|
||
| /** Tests that the compiler recognizes that [suspendCancellableCoroutine] invokes its block exactly once. */ | ||
| @Test | ||
| fun testSuspendCancellableCoroutineContract() = runTest { | ||
| val i: Int | ||
| suspendCancellableCoroutine { cont -> | ||
| i = 1 | ||
| cont.resume(Unit) | ||
| } | ||
| assertEquals(1, i) | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you set your editor to add newlines?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not at all straightforward, I'm afraid. Of course, I will make sure to do that if I learn that the lack of newlines in Kotlin files leads to some actual problems. |
||
Uh oh!
There was an error while loading. Please reload this page.
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.
by allowing the
valvariable(the point of focus could be not immediately clear in future)
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.
Given that the whole test is five lines, there isn't a lot of room for misinterpreting what the test does, especially given that the KDoc describes that we're testing the
EXACTLY_ONCEcontract.