mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-10 00:21:35 +00:00
In Kotlin 1.1 and before, there were no nullability assertions on extension receivers, because receiver is resolved with NO_EXPECTED_TYPE. So, if an expression of platform type is passed as an extension receiver to a non-private function, it would fail with IllegalArgumentException. However, if the function is private, then we generated no parameter assertions under assumption that such function can be called from Kotlin only, and all arguments are checked on the call site. Thus 'null' could propagate indefinitely. In Kotlin 1.2, we do the following: - Generate nullability assertions for expression receivers. NB nullability assertions are stored for ReceiverValue instances, not for expressions: given expression can act as receiver in different calls, each with an expected receiver type of its own. - Generate nullability assertions for extension receivers of private operator functions. NB it still can throw NPE for some particular "optimized" cases, but at least those nulls would not propagate indefinitely. This behavior is disabled by an "advanced" command-line option '-Xno-receiver-assertions'.