Incorporate PR from Steven Schäfer into IrType-based implicit cast
insertion (commit 17b925636e8717e7648c5d7b792c6ab4d18f776d).
NB this still uses originalKotlinType to determine if the type was
nullability flexible. It is somewhat error-prone and something we want
to get rid of. However, it boils down to some design questions related
to implicit null checks in Kotlin - e.g., it might be Ok to just treat
nullability flexible type `T!` as `T?` in IR, generate null checks for
all usages of type `T?` where a non-null type is expected, and later
eliminate the null checks that are redundant according to the (quite
conservative) criterion in the redundant null check elimination.
Given an expression with SAM conversion, e.g.:
```
fun test(a: Any?) {
if (a is () -> Unit) {
Runnable(a).run()
}
}
```
Here `Runnable(a)` expects `a` to be a value of functional type
`() -> Unit` (and corresponding type check makes smart cast possible).
Relation between `Runnable` and `() -> Unit` is somewhat non-trivial,
is implemented in terms of KotlinTypes and DeclarationDescriptors,
and so should be encapsulated in psi2ir if possible.
Thus, psi2ir generates IR such as
```
TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION ...
TYPE_OP type=kotlin.Function0<kotlin.Unit> origin=IMPLICIT_CAST ...
[| a |]
```
and InsertImplicitCasts knows that IMPLICIT_CAST actually might be
unnecessary (which also allows to use InsertImplicitCasts in some other
context that might require IMPLICIT_CAST rewriting, such as inlining).
In 192 it's important to have service registered since
https://github.com/JetBrains/intellij-community/commit/f204718c885034bc2fa4be4b281ff4bbd5fa4ef4
Caused by: java.lang.IllegalArgumentException: Argument for @NotNull parameter 'value' of com/intellij/openapi/util/UserDataHolderBase.putUserDataIfAbsent must not be null
at com.intellij.openapi.util.UserDataHolderBase.$$$reportNull$$$0(UserDataHolderBase.java)
at com.intellij.openapi.util.UserDataHolderBase.putUserDataIfAbsent(UserDataHolderBase.java)
at com.intellij.openapi.util.NotNullLazyKey.getValue(NotNullLazyKey.java:41)
at com.intellij.lang.injection.InjectedLanguageManager.getInstance(InjectedLanguageManager.java:41)
at com.intellij.psi.impl.PsiCachedValue.isVeryPhysical(PsiCachedValue.java:74)
at com.intellij.psi.impl.PsiCachedValue.anyChangeImpliesPsiCounterChange(PsiCachedValue.java:57)
Reproduced with Fir2IrTextTestGenerated