Added 'LowPriorityInOverloadResolution' annotation

This commit is contained in:
Svetlana Isakova
2015-10-16 17:51:27 +03:00
parent 1cfb7d8f57
commit ded62686a0
5 changed files with 33 additions and 2 deletions
@@ -25,9 +25,9 @@ import org.jetbrains.kotlin.psi.Call
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.psi.doNotAnalyze
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getUnaryPlusOrMinusOperatorFunctionName
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isConventionCall
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isOrOverridesSynthesized
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getUnaryPlusOrMinusOperatorFunctionName
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.collectors.CallableDescriptorCol
import org.jetbrains.kotlin.resolve.calls.tasks.collectors.CallableDescriptorCollectors
import org.jetbrains.kotlin.resolve.calls.tasks.collectors.filtered
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
import org.jetbrains.kotlin.resolve.descriptorUtil.hasLowPriorityInOverloadResolution
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
@@ -480,7 +481,7 @@ public class TaskPrioritizer(
override fun getPriority(candidate: ResolutionCandidate<D>)
= if (hasImplicitDynamicReceiver(candidate)) 0
else (if (isVisible(candidate)) 2 else 0) + (if (isSynthesized(candidate)) 0 else 1)
else (if (!isVisible(candidate) || hasLowPriority(candidate)) 0 else 2) + (if (isSynthesized(candidate)) 0 else 1)
override fun getMaxPriority() = 3
@@ -492,6 +493,11 @@ public class TaskPrioritizer(
return Visibilities.isVisible(receiverValue, candidateDescriptor, context.scope.ownerDescriptor)
}
private fun hasLowPriority(candidate: ResolutionCandidate<D>?): Boolean {
if (candidate == null) return false
return candidate.descriptor.hasLowPriorityInOverloadResolution()
}
private fun isSynthesized(candidate: ResolutionCandidate<D>): Boolean {
val descriptor = candidate.getDescriptor()
return descriptor is CallableMemberDescriptor && isOrOverridesSynthesized(descriptor)
@@ -0,0 +1,7 @@
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
fun foo(i: Int) = 1
fun foo(a: Any) = 2
fun box() = if (foo(1) == 2) "OK" else "fail"
@@ -130,6 +130,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib(fileName);
}
@TestMetadata("resolveWithLowPriorityAnnotation.kt")
public void testResolveWithLowPriorityAnnotation() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/annotations/resolveWithLowPriorityAnnotation.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("varargInAnnotationParameter.kt")
public void testVarargInAnnotationParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/annotations/varargInAnnotationParameter.kt");
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.resolve.descriptorUtil
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotated
import org.jetbrains.kotlin.name.FqName
@@ -28,6 +29,10 @@ private val EXACT_ANNOTATION_FQ_NAME = FqName("kotlin.internal.Exact")
public fun Annotated.hasExactAnnotation(): Boolean = annotations.hasAnnotation(EXACT_ANNOTATION_FQ_NAME)
private val LOW_PRIORITY_IN_OVERLOAD_RESOLUTION_FQ_NAME = FqName("kotlin.internal.LowPriorityInOverloadResolution")
public fun CallableDescriptor.hasLowPriorityInOverloadResolution(): Boolean = annotations.hasAnnotation(LOW_PRIORITY_IN_OVERLOAD_RESOLUTION_FQ_NAME)
private val ONLY_INPUT_TYPES_FQ_NAME = FqName("kotlin.internal.OnlyInputTypes")
public fun TypeParameterDescriptor.hasOnlyInputTypesAnnotation(): Boolean = annotations.hasAnnotation(ONLY_INPUT_TYPES_FQ_NAME)
@@ -30,6 +30,13 @@ internal annotation class NoInfer
@Retention(AnnotationRetention.SOURCE)
internal annotation class Exact
/**
* Specifies that a corresponding member has the lowest priority in overload resolution.
*/
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.SOURCE)
internal annotation class LowPriorityInOverloadResolution
/**
* The value of this type parameter should be mentioned in input types (argument types, receiver type or expected type).
*/