Create hacks for magic annotations NoInfer, OnlyInputTypes and LowPriorityInOverloadResolution.

This commit is contained in:
Stanislav Erokhin
2015-11-25 16:49:56 +03:00
parent 1be4f795ed
commit f0cefd5583
6 changed files with 93 additions and 0 deletions
@@ -49,6 +49,35 @@ internal class ConstraintSystemImpl(
override fun hasContradiction() = hasParameterConstraintError() || hasConflictingConstraints()
|| hasCannotCaptureTypesError() || hasTypeInferenceIncorporationError()
// hacks for library migration todo: remove its later
|| hasTypeParameterWithUnsatisfiedOnlyInputTypesError()
/**
* Hacks above are needed for the following example:
*
* @kotlin.jvm.JvmName("containsAny")
* @kotlin.internal.LowPriorityInOverloadResolution
* public operator fun <T> Iterable<T>.contains(element: T): Boolean
*
* public operator fun <@kotlin.internal.OnlyInputTypes T> Iterable<T>.contains(element: T): Boolean
*
* fun test() = listOf(1).contains("")
*
* When we resolve call `contains`, we should choose candidate before we complete inference.
* Because of this we can't check OnlyInputTypes when we trying choose candidate.
* Now we do this check in this moment, but it is incorrect and we should remove it later.
*
* Call !satisfyInitialConstraints() in hasTypeInferenceIncorporationError() is needed for this example:
* @kotlin.jvm.JvmName("containsAny")
* @kotlin.internal.LowPriorityInOverloadResolution
* public operator fun <T> Iterable<T>.contains(element: T): Boolean
*
* public operator fun <T> Iterable<T>.contains(element: @kotlin.internal.NoInfer T)
*
* fun test() = listOf(1).contains("")
*
* It is also incorrect, because we can get additional constraints on T after we resolve call `contains`.
*/
override fun hasViolatedUpperBound() = !isSuccessful() && filterConstraintsOut(TYPE_BOUND_POSITION).status.isSuccessful()
@@ -0,0 +1,15 @@
//!DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.jvm.JvmName("containsAny")
@kotlin.internal.LowPriorityInOverloadResolution
public fun <T> Iterable<T>.contains1(element: T): Int = null!!
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
public fun <T> Iterable<T>.contains1(element: @kotlin.internal.NoInfer T): Boolean = null!!
fun test() {
val a: Int = listOf(1).contains1("")
val b: Boolean = listOf(1).contains1(1)
}
@@ -0,0 +1,5 @@
package
public fun test(): kotlin.Unit
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) @kotlin.jvm.JvmName(name = "containsAny") @kotlin.internal.LowPriorityInOverloadResolution() public fun </*0*/ T> kotlin.Iterable<T>.contains1(/*0*/ element: T): kotlin.Int
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ T> kotlin.Iterable<T>.contains1(/*0*/ element: T): kotlin.Boolean
@@ -0,0 +1,25 @@
//!DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.jvm.JvmName("containsAny")
@kotlin.internal.LowPriorityInOverloadResolution
public fun <T> Iterable<T>.contains1(element: T): Int = null!!
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
public fun <@kotlin.internal.OnlyInputTypes T> Iterable<T>.contains1(element: T): Boolean = null!!
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@JvmName("getAny")
@kotlin.internal.LowPriorityInOverloadResolution
public fun <K, V> Map<K, V>.get1(key: Any?): Int = null!!
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
public fun <@kotlin.internal.OnlyInputTypes K, V> Map<out K, V>.get1(key: K): V? = null!!
fun test(map: Map<Int, String>) {
val a: Int = listOf(1).contains1("")
val b: Boolean = listOf(1).contains1(1)
val c: Int = map.get1("")
val d: String? = map.get1(1)
}
@@ -0,0 +1,7 @@
package
public fun test(/*0*/ map: kotlin.Map<kotlin.Int, kotlin.String>): kotlin.Unit
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) @kotlin.jvm.JvmName(name = "containsAny") @kotlin.internal.LowPriorityInOverloadResolution() public fun </*0*/ T> kotlin.Iterable<T>.contains1(/*0*/ element: T): kotlin.Int
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ T> kotlin.Iterable<T>.contains1(/*0*/ element: T): kotlin.Boolean
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) @kotlin.jvm.JvmName(name = "getAny") @kotlin.internal.LowPriorityInOverloadResolution() public fun </*0*/ K, /*1*/ V> kotlin.Map<K, V>.get1(/*0*/ key: kotlin.Any?): kotlin.Int
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ K, /*1*/ V> kotlin.Map<out K, V>.get1(/*0*/ key: K): V?
@@ -708,12 +708,24 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
doTest(fileName);
}
@TestMetadata("noInferAndLowPriority.kt")
public void testNoInferAndLowPriority() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAndLowPriority.kt");
doTest(fileName);
}
@TestMetadata("noInferAnnotation.kt")
public void testNoInferAnnotation() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAnnotation.kt");
doTest(fileName);
}
@TestMetadata("onlyInputTypesAndLowPriority.kt")
public void testOnlyInputTypesAndLowPriority() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAndLowPriority.kt");
doTest(fileName);
}
@TestMetadata("onlyInputTypesAnnotationWithPlatformTypes.kt")
public void testOnlyInputTypesAnnotationWithPlatformTypes() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/onlyInputTypesAnnotationWithPlatformTypes.kt");