Version 1.6-rfc+0.1
Some functions or parameters of functions in the standard library are annotated with the special @BuilderInference
annotation, making calls to these functions eligible for the special kind of type inference: builder-style type inference. In order to allow builder-style inference for a function parameter, this parameter must hold the following properties:
@BuilderInference
annotation.In essence, the builder-style inference allows a receiver of an extension lambda parameter to be inferred from its usage in addition to standard type information sources. For a call to an eligible function with a lambda parameter the inference is performed as described above, but the type parameters of the receiver parameter of the lambda expression are postponed till the body of the lambda expression is proceeded. After the inference of statements inside the lambda body, these parameters are inferred using an additional type inference step:
@BuilderInference
annotation, the type constraints are collected and gathered into a single constraint system;Note: notable examples of builder-style inference-enabled functions are
kotlin.sequence
andkotlin.iterator
. See standard library documentation for details.