Skip to content

Commit fa08069

Browse files
committed
KEEP-0443-suspend-CoroutineContext-context-parameter: Make the main point of the proposal more clear
Avoid mixing user code and what the compiler generates in one snippet
1 parent 36dab67 commit fa08069

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

proposals/KEEP-0443-suspend-CoroutineContext-context-parameter.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,25 @@ Goals:
108108
3. Bridge `suspend` and context parameters features together, making the language to work as a whole
109109

110110
The proposal is to treat all `suspend` functions
111-
as if their bodies were implicitly enclosed within `context(getContinuation_compiler_intrinsic().context) { /* the rest of the body... */ }` stdlib function:
111+
as if their bodies were implicitly enclosed within `context(getContinuation_compiler_intrinsic().context) { /* the rest of the body... */ }` block:
112112

113113
```kotlin
114-
suspend fun computation() = /* implicitly enclosed within */ context(getContinuation_compiler_intrinsic().context) {
115-
foo() // Green code
114+
suspend fun computation() {
115+
foo() // The result of this proposal is that the code becomes green. In the current Kotlin, the code is red
116116
}
117117

118118
context(_: CoroutineContext)
119119
fun foo() {}
120120
```
121121

122+
The code above works because the compiler encloses the `suspend` function body within the `context` block:
123+
124+
```kotlin
125+
suspend fun computation() = context(getContinuation_compiler_intrinsic().context) {
126+
foo()
127+
}
128+
```
129+
122130
### `coroutineContext` stdlib property
123131

124132
Currently, `suspend` properties are disallowed to encourage users to declare only such properties which are cheap to compute.

0 commit comments

Comments
 (0)