Skip to content

Commit 5803ed6

Browse files
committed
Update property examples
1 parent 425a3d0 commit 5803ed6

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

proposals/context-parameters.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
This is an updated proposal for [KEEP-259](https://github.com/Kotlin/KEEP/issues/259), formerly known as _context receivers_. The new design addresses the issues raised by the users of the prototype implementing that previous iteration of the design and across the community at large.
1111

12-
This document is not (yet) formally a KEEP, since it lacks some of the technical elements. Those are going to be provided at a later time, but we thought it would be interesting to open the discussion even if the design is not fully formalized.
13-
1412
### Summary of changes from the [previous proposal](https://github.com/Kotlin/KEEP/issues/259)
1513

1614
1. Introduction of named context parameters,
@@ -65,7 +63,7 @@ context(analysisScope: AnalysisScope)
6563
fun Type.equalTo(other: Type): Boolean = ...
6664

6765
context(_: AnalysisScope)
68-
val Type.isBoolean: Boolean = this.equalTo(BuiltIns.Boolean)
66+
val Type.isBoolean: Boolean get() = this.equalTo(BuiltIns.Boolean)
6967
```
7068

7169
**§1.2** *(restrictions)*:
@@ -84,17 +82,11 @@ Properties declared with context parameters have [**no** _backing field_](https:
8482

8583
```kotlin
8684
// not allowed (property with initializer)
87-
context(users: UserRepository)
88-
val firstUser: User? = users.getById(1)
85+
context(_: AnalysisScope)
86+
val Type.isBoolean: Boolean = this.equalTo(BuiltIns.Boolean)
8987
```
9088

91-
It is **not** possible to declare context parameters solely for the getter or setter. It is unclear how a property reference (`::firstUser`) should behave if the set of context parameters differs between the getter and the setter.
92-
93-
```kotlin
94-
// not allowed (context parameter in getter)
95-
val firstUser: User?
96-
context(users: UserRepository) get() = users.getById(1)
97-
```
89+
It is **not** possible to declare context parameters solely for the getter or setter. It is unclear how a property reference should behave if the set of context parameters differs between the getter and the setter.
9890

9991
At this point, properties with context parameters may **not** use [_delegation_](https://kotlinlang.org/spec/declarations.html#delegated-property-declaration). It is unclear at this point what should be the correct semantics for such a declaration.
10092

0 commit comments

Comments
 (0)