Report type inference error

when inference failed with 'NoInfer' annotation
This commit is contained in:
Svetlana Isakova
2015-10-17 16:37:01 +03:00
parent 5ab3dd1716
commit 4c85b69c88
4 changed files with 13 additions and 10 deletions
@@ -10,21 +10,23 @@ fun <T> @kotlin.internal.NoInfer T.test2(t1: T): T = t1
fun <T> test3(t1: @kotlin.internal.NoInfer T): T = t1
fun usage() {
test1(1, <!TYPE_MISMATCH!>"312"<!>)
<!TYPE_MISMATCH!>1<!>.test2("")
<!TYPE_INFERENCE_INCORPORATION_ERROR!>test1<!>(1, <!TYPE_MISMATCH!>"312"<!>)
<!TYPE_MISMATCH!>1<!>.<!TYPE_INFERENCE_INCORPORATION_ERROR!>test2<!>("")
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test3<!>("")
}
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun <T> List<T>.contains1(e: @kotlin.internal.NoInfer T): Boolean = true
fun test(l: List<Number>) {
l.contains1(<!TYPE_MISMATCH!>""<!>)
fun test(i: Int?, a: Any, l: List<Int>) {
l.<!TYPE_INFERENCE_INCORPORATION_ERROR!>contains1<!>(<!TYPE_MISMATCH!>a<!>)
l.<!TYPE_INFERENCE_INCORPORATION_ERROR!>contains1<!>(<!TYPE_MISMATCH!>""<!>)
l.contains1(<!TYPE_MISMATCH!>i<!>)
}
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun <T> assertEquals1(e1: T, e2: @kotlin.internal.NoInfer T): Boolean = true
fun test(s: String) {
assertEquals1(s, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>11<!>)
<!TYPE_INFERENCE_INCORPORATION_ERROR!>assertEquals1<!>(s, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>11<!>)
}
@@ -1,7 +1,7 @@
package
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ T> assertEquals1(/*0*/ e1: T, /*1*/ e2: T): kotlin.Boolean
public fun test(/*0*/ l: kotlin.List<kotlin.Number>): kotlin.Unit
public fun test(/*0*/ i: kotlin.Int?, /*1*/ a: kotlin.Any, /*2*/ l: kotlin.List<kotlin.Int>): kotlin.Unit
public fun test(/*0*/ s: kotlin.String): kotlin.Unit
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ T> test1(/*0*/ t1: T, /*1*/ t2: T): T
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ T> test3(/*0*/ t1: T): T
@@ -18,16 +18,16 @@ 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
import org.jetbrains.kotlin.types.JetType
private val NO_INFER_ANNOTATION_FQ_NAME = FqName("kotlin.internal.NoInfer")
public fun Annotated.hasNoInferAnnotation(): Boolean = annotations.hasAnnotation(NO_INFER_ANNOTATION_FQ_NAME)
public fun JetType.hasNoInferAnnotation(): Boolean = annotations.hasAnnotation(NO_INFER_ANNOTATION_FQ_NAME)
private val EXACT_ANNOTATION_FQ_NAME = FqName("kotlin.internal.Exact")
public fun Annotated.hasExactAnnotation(): Boolean = annotations.hasAnnotation(EXACT_ANNOTATION_FQ_NAME)
public fun JetType.hasExactAnnotation(): Boolean = annotations.hasAnnotation(EXACT_ANNOTATION_FQ_NAME)
private val LOW_PRIORITY_IN_OVERLOAD_RESOLUTION_FQ_NAME = FqName("kotlin.internal.LowPriorityInOverloadResolution")
@@ -293,7 +293,6 @@ public class ConstraintSystemImpl : ConstraintSystem {
if (isErrorOrSpecialType(subType, constraintPosition) || isErrorOrSpecialType(superType, constraintPosition)) return
if (subType == null || superType == null) return
if (subType.hasNoInferAnnotation() || superType.hasNoInferAnnotation()) return
if ((subType.hasExactAnnotation() || superType.hasExactAnnotation()) && (constraintKind != EQUAL)) {
return doAddConstraint(EQUAL, subType, superType, constraintContext, typeCheckingProcedure)
}
@@ -340,6 +339,8 @@ public class ConstraintSystemImpl : ConstraintSystem {
if (constraintContext.initial) {
storeInitialConstraint(constraintKind, subType, superType, constraintPosition)
}
if (subType.hasNoInferAnnotation() || superType.hasNoInferAnnotation()) return
simplifyConstraint(newSubType, superType)
}