Fixed auto-import of operator functions broken before + fixed bug in its implementation
This commit is contained in:
@@ -84,8 +84,6 @@ public class ReferenceVariantsHelper(
|
||||
val pair = getExplicitReceiverData(expression)
|
||||
if (pair != null) {
|
||||
val (receiverExpression, callType) = pair
|
||||
fun filterIfInfix(descriptor: DeclarationDescriptor)
|
||||
= if (callType == CallType.INFIX) descriptor is SimpleFunctionDescriptor && descriptor.getValueParameters().size == 1 else true
|
||||
|
||||
// Process as call expression
|
||||
val descriptors = HashSet<DeclarationDescriptor>()
|
||||
@@ -93,7 +91,7 @@ public class ReferenceVariantsHelper(
|
||||
val qualifier = context[BindingContext.QUALIFIER, receiverExpression]
|
||||
if (qualifier != null) {
|
||||
// It's impossible to add extension function for package or class (if it's class object, expression type is not null)
|
||||
qualifier.scope.getDescriptorsFiltered(kindFilter exclude DescriptorKindExclude.Extensions, nameFilter).filterTo(descriptors, ::filterIfInfix)
|
||||
qualifier.scope.getDescriptorsFiltered(kindFilter exclude DescriptorKindExclude.Extensions, nameFilter).filterTo(descriptors) { callType.canCall(it) }
|
||||
}
|
||||
|
||||
val expressionType = if (shouldCastToRuntimeType)
|
||||
@@ -106,7 +104,7 @@ public class ReferenceVariantsHelper(
|
||||
|
||||
val mask = kindFilter.withoutKinds(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK).exclude(DescriptorKindExclude.Extensions)
|
||||
for (variant in SmartCastUtils.getSmartCastVariantsWithLessSpecificExcluded(receiverValue, context, dataFlowInfo)) {
|
||||
variant.getMemberScope().getDescriptorsFiltered(mask, nameFilter).filterTo(descriptors, ::filterIfInfix)
|
||||
variant.getMemberScope().getDescriptorsFiltered(mask, nameFilter).filterTo(descriptors) { callType.canCall(it) }
|
||||
}
|
||||
|
||||
descriptors.addCallableExtensions(resolutionScope, receiverValue, dataFlowInfo, callType, kindFilter, nameFilter)
|
||||
@@ -204,6 +202,8 @@ public class ReferenceVariantsHelper(
|
||||
CallType.NORMAL
|
||||
}
|
||||
|
||||
is JetUnaryExpression -> CallType.UNARY
|
||||
|
||||
else -> return null
|
||||
}
|
||||
return receiverExpression to callType
|
||||
|
||||
@@ -24,11 +24,23 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.calls.smartcasts.SmartCastUtils
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
|
||||
public enum class CallType {
|
||||
NORMAL
|
||||
SAFE
|
||||
INFIX
|
||||
|
||||
INFIX {
|
||||
override fun canCall(descriptor: DeclarationDescriptor)
|
||||
= descriptor is SimpleFunctionDescriptor && descriptor.getValueParameters().size == 1
|
||||
}
|
||||
|
||||
UNARY {
|
||||
override fun canCall(descriptor: DeclarationDescriptor)
|
||||
= descriptor is SimpleFunctionDescriptor && descriptor.getValueParameters().size == 0
|
||||
}
|
||||
|
||||
public open fun canCall(descriptor: DeclarationDescriptor): Boolean = true
|
||||
}
|
||||
|
||||
public fun CallableDescriptor.substituteExtensionIfCallable(receivers: Collection<ReceiverValue>,
|
||||
@@ -54,10 +66,7 @@ public fun CallableDescriptor.substituteExtensionIfCallable(
|
||||
dataFlowInfo: DataFlowInfo
|
||||
): Collection<CallableDescriptor> {
|
||||
if (!receiver.exists()) return listOf()
|
||||
|
||||
if (callType == CallType.INFIX && (this !is SimpleFunctionDescriptor || getValueParameters().size() != 1)) {
|
||||
return listOf()
|
||||
}
|
||||
if (!callType.canCall(this)) return listOf()
|
||||
|
||||
var types = SmartCastUtils.getSmartCastVariants(receiver, bindingContext, dataFlowInfo).stream()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user