raulraja
11/12/2019, 11:03 PMFunctionDescriptor
that points to something like:
fun <A> A.show(): String = toString()
is a valid candidate to be applied in the expression
val s: String = 1.show()
When I have A
and Int
as `KotlinType`s and I ask if Int
is a subtype of A
it always says no despite being a generic type. This makes sense since it could refer to any other type. What service does the Kotlin compiler use to see if a generic function is in bounds or applicable to a type? Any help is appreciated, thanks.dmitriy.novozhilov
11/13/2019, 9:23 AMResolutionParts.kt
where defined all checks that resolve applies to some candidate when it resolves some callraulraja
11/13/2019, 2:03 PMraulraja
11/13/2019, 11:21 PMdmitriy.novozhilov
11/14/2019, 7:38 AM1.show()
), or I misunderstand your problem?raulraja
11/14/2019, 6:38 PMFunctionDescriptor
for:
fun <A, B> <http://A.to|A.to>(): B = TODO()
And I want to know if two `KotlinType`s are applicable to that FunctionDescriptor. I could get the PSI out of the FunctionDescriptor
but that is not the Psi for the Call unless I could construct a fake call for it.raulraja
11/14/2019, 6:42 PMInt
and String
are fine because the function is fully polymorphic but if I ask with the KotlinTypeChecker
if Int : A
it yields false because it’s a type argument.
Given it’s not one function but a List of functions I need to run over to find a candidate I thought I could do this with resolution but at this point I have no PSI call because what I’m trying to proof is to check if the function descriptor is applicable to those two types one being the receiver and the other the return type. In this case it should have been applicable since this is a universal polymorphic function for all A and B but using the type checker to check for a match isn’t enough.
I also tried this:
val appliedConversion = conversion.substituteAndApproximateCapturedTypes(
NewTypeSubstitutorByConstructorMap(listOfNotNull(fromSub, toSub).toMap()),
TypeApproximator(conversion.module.builtIns)
)
raulraja
11/14/2019, 6:46 PMfun FunctionDescriptor.applyProof2(
session: ResolveSession,
subType: KotlinType,
superType: KotlinType
): OverloadResolutionResults<FunctionDescriptor> {
val call: Call = TODO() //how to get this
val extensionReceiver = ExtensionReceiver(this, subType, null)
val newCall = ResolvedCallImpl(
call,
this,
null, extensionReceiver, ExplicitReceiverKind.EXTENSION_RECEIVER,
null, DelegatingBindingTrace(BindingTraceContext().bindingContext, "Temporary trace for unwrapped suspension function"),
TracingStrategy.EMPTY, MutableDataFlowInfoForArguments.WithoutArgumentsCheck(DataFlowInfo.EMPTY)
)
val functionScope = session.declarationScopeProvider.getResolutionScopeForDeclaration(call) // TODO get the PSI
val innerScope = FunctionDescriptorUtil.getFunctionInnerScope(functionScope, this, session.trace, OverloadChecker(TypeSpecificityComparator.NONE))
return componentProvider.get<PSICallResolver>().runResolutionAndInferenceForGivenCandidates(
context = BasicCallResolutionContext.create(
... ///TODO not sure how to bring these instances to life here
)
resolutionCandidates = proofs.values.map { ResolutionCandidate.create(call, it) },
tracingStrategy = TracingStrategy.EMPTY
)
}
dmitriy.novozhilov
11/14/2019, 6:57 PMTypeParameterDescriptor.getUpperBounds()
)raulraja
11/14/2019, 8:37 PMImran/Malic
11/16/2019, 8:42 AMKotlinType
regarding Descriptors. Maybe they are somehow helpful for you @raulraja https://github.com/arrow-kt/arrow-meta/blob/46db55089d1713d8be88d3beb7888d2c85f929f5/idea-plugin/src/main/kotlin/arrow/meta/ide/dsl/editor/inspection/InspectionUtilitySyntax.kt#L52
I wish I could be of more help 🙂