Context receivers, previously known under the name of "multiple receivers", are designed to make functions, properties, and classes context-dependent (or contextual) by adding context receivers to their declaration. A contextual declaration:
- Requires all declared context receivers to be present in a caller’s scope as implicit receivers.
- Brings declared context receivers into its body scope as implicit receivers.
Goals
Remove all limitations of member extensions for writing contextual abstractions
- Support top-level (non-member) contextual functions and properties
- Support adding contextual function and properties to 3rd party context classes
- Support multiple contexts
Make blocks of code with multiple receivers representable in Kotlin's type system
Separate the concepts of extension and dispatch receivers from the concept of context receivers
- Context receivers should not change the meaning of unqualified this expression
- Multiple contexts should not be ordered during resolution, resolution ambiguities shall be reported
Design a scalable resolution algorithm with respect to the number of receivers
- Call resolution should not be exponential in the number of context receivers