why I essentially want is an implicit type convers...
# arrow-meta
r
why I essentially want is an implicit type conversion which currently is workaround with a cast even though we have proof that OptionOf is only extended by Option
d
I can tell, where you can find places what you need in new inference: Entry point to NI is class
PsiCallResolver
, you can start from there Resulting
resolvedCall
is created in` KotlinToResolvedCallTransformer.transformAndReport` method But I assume that you can achieve functionality that you want via smartcast mechanism by adding to context info about that
x is Option<A>
without changing algorithm of descriptors creating (look at
KotlinToResolvedCallTransformer.runArgumetnsCheck
But unfortunately for you, as I know, there is no extension points in that part of compiler
r
thanks @dmitriy.novozhilov, this is great info. At this point I’m happy hijacking the component registry fields via reflection if needed to install my own wrapper. In practice if there was a single extension point in the component registry you could replace any compiler service except for those that are statically created right?
😱 1
I have for example replaced the
KotlinTypeChecker.DEFAULT
with:
Copy code
class KindAwareTypeChecker(val typeChecker: KotlinTypeChecker) : KotlinTypeChecker by typeChecker {
  override fun isSubtypeOf(p0: KotlinType, p1: KotlinType): Boolean {
    println("KindAwareTypeChecker.isSubtypeOf: $p0 <-> $p1")
    return typeChecker.isSubtypeOf(p0, p1)
  }

  override fun equalTypes(p0: KotlinType, p1: KotlinType): Boolean {
    println("KindAwareTypeChecker.equalTypes: $p0 <-> $p1")
    return typeChecker.equalTypes(p0, p1)
  }
}
using java reflection
yeah it’s awful
d
It's look like a dirty but working hack
Note that some part of new inferences uses it's own typechecker
r
makes sense I was just testing it works, I will remove it if I can figure out how to add the smartcast
So the approach is either intercept the PsiCallResolver or the KotlinToResolvedCallTransformer creation. I’m looking at
runArgumentsCheck
but not sure where it would add info to the context
is that
replaceDataFlowInfo
?
👌 1
Do you think I could do this if I can register an instance of
DataFlowValueFactory
or something similar?. Intercepting
KotlinToResolvedCallTransformer.runArgumentsChecks
does not seem an option. If then I realize this can’t be done in this class due to lack of access how could I intercept the
PsiCallResolver
instead? thanks!
d
Maybe you can try override
DataFlowAnalyzer
?
checkType
is most interesting method for you, inside it compiler writes to bindingContext info about smartcasts