[NI] Record DFI for callable reference arguments

#KT-31941 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2019-06-17 16:40:50 +03:00
parent 1f70284b18
commit 8fe632f52b
9 changed files with 119 additions and 14 deletions
@@ -1659,6 +1659,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
runTest("compiler/testData/diagnostics/tests/callableReference/classVsPackage.kt");
}
@TestMetadata("correctInfoAfterArrayLikeCall.kt")
public void testCorrectInfoAfterArrayLikeCall() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
}
@TestMetadata("ea81649_errorPropertyLHS.kt")
public void testEa81649_errorPropertyLHS() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/ea81649_errorPropertyLHS.kt");
@@ -1684,6 +1689,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
runTest("compiler/testData/diagnostics/tests/callableReference/kt25433.kt");
}
@TestMetadata("kt31981.kt")
public void testKt31981() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/kt31981.kt");
}
@TestMetadata("kt7430_wrongClassOnLHS.kt")
public void testKt7430_wrongClassOnLHS() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.kt");
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -288,7 +289,8 @@ class ResolvedAtomCompleter(
}
// TODO: probably we should also record key 'DATA_FLOW_INFO_BEFORE', see ExpressionTypingVisitorDispatcher.getTypeInfo
topLevelTrace.recordType(callableReferenceExpression, resultType)
val typeInfo = createTypeInfo(resultType, resolvedAtom.atom.psiCallArgument.dataFlowInfoAfterThisArgument)
topLevelTrace.record(BindingContext.EXPRESSION_TYPE_INFO, callableReferenceExpression, typeInfo)
topLevelTrace.record(BindingContext.PROCESSED, callableReferenceExpression)
doubleColonExpressionResolver.checkReferenceIsToAllowedMember(
@@ -0,0 +1,16 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty1
class DTO {
val q: Int = 0
operator fun get(prop: KProperty1<*, Int>): Int = 0
}
fun foo(intDTO: DTO?, p: KProperty1<*, Int>) {
if (intDTO != null) {
<!DEBUG_INFO_SMARTCAST!>intDTO<!>[DTO::q]
<!DEBUG_INFO_SMARTCAST!>intDTO<!>.q
}
}
@@ -0,0 +1,12 @@
package
public fun foo(/*0*/ intDTO: DTO?, /*1*/ p: kotlin.reflect.KProperty1<*, kotlin.Int>): kotlin.Unit
public final class DTO {
public constructor DTO()
public final val q: kotlin.Int = 0
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun get(/*0*/ prop: kotlin.reflect.KProperty1<*, kotlin.Int>): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,23 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KProperty1
import kotlin.reflect.KMutableProperty1
class Inv<T> {
val size: Int = 0
}
class DTO<T> {
val test: Inv<T>? = null
var q: Int = 0
operator fun <R> get(prop: KProperty1<*, R>): R = TODO()
operator fun <R> set(prop: KMutableProperty1<*, R>, value: R) { }
}
fun main(intDTO: DTO<Int>?) {
if (intDTO != null) {
<!DEBUG_INFO_SMARTCAST!>intDTO<!>[DTO<Int>::q] = <!DEBUG_INFO_SMARTCAST!>intDTO<!>[DTO<Int>::test]!!.size
<!DEBUG_INFO_SMARTCAST!>intDTO<!>[DTO<Int>::q] = <!DEBUG_INFO_SMARTCAST!>intDTO<!>[DTO<Int>::test]!!.size
}
}
@@ -0,0 +1,22 @@
package
public fun main(/*0*/ intDTO: DTO<kotlin.Int>?): kotlin.Unit
public final class DTO</*0*/ T> {
public constructor DTO</*0*/ T>()
public final var q: kotlin.Int
public final val test: Inv<T>? = null
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun </*0*/ R> get(/*0*/ prop: kotlin.reflect.KProperty1<*, R>): R
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final operator fun </*0*/ R> set(/*0*/ prop: kotlin.reflect.KMutableProperty1<*, R>, /*1*/ value: R): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Inv</*0*/ T> {
public constructor Inv</*0*/ T>()
public final val size: kotlin.Int = 0
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -20,8 +20,8 @@ fun case_1(x: Any?) {
if (x is String) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any? & kotlin.String")!>x<!>
val y = if (true) Class::fun_1 else Class::fun_1
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>x<!>
val z: String = <!TYPE_MISMATCH!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any? & kotlin.String")!>x<!>
val z: String = <!DEBUG_INFO_SMARTCAST!>x<!>
}
}
@@ -38,8 +38,8 @@ fun case_2(x: Any?, b: Boolean?) {
false -> Class::fun_2
null -> Class::fun_3
}
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>x<!>
val z: Any = <!TYPE_MISMATCH!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any?")!>x<!>
val z: Any = <!DEBUG_INFO_SMARTCAST!>x<!>
}
/*
@@ -53,8 +53,8 @@ fun case_3(x: Any?, b: Boolean?) {
val y = when (b) {
else -> Class::fun_1
}
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>x<!>
val z: Int = <!TYPE_MISMATCH!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any? & kotlin.Int")!>x<!>
val z: Int = <!DEBUG_INFO_SMARTCAST!>x<!>
}
// TESTCASE NUMBER: 4
@@ -77,8 +77,8 @@ fun case_5(x: Any?, b: Class) {
x as Int
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any? & kotlin.Int")!>x<!>
val y = if (true) b::fun_1 else b::fun_1
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>x<!>
val z: Int = <!TYPE_MISMATCH!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any? & kotlin.Int")!>x<!>
val z: Int = <!DEBUG_INFO_SMARTCAST!>x<!>
}
/*
@@ -91,9 +91,9 @@ fun case_6(x: Any?, b: Class) {
val z1 = x
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any? & kotlin.Int")!>x<!>
val y = if (true) b::fun_1 else b::fun_1
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>z1<!>
val z2: Int = <!TYPE_MISMATCH!>z1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any? & kotlin.Int")!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any? & kotlin.Int")!>z1<!>
val z2: Int = <!DEBUG_INFO_SMARTCAST!>z1<!>
}
/*
@@ -106,8 +106,8 @@ fun case_7(x: Any?) {
if (x is String) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any? & kotlin.String")!>x<!>
val y = if (true) ::case_7_1 else ::case_7_1
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any?")!>x<!>
val z: String = <!TYPE_MISMATCH!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.Any? & kotlin.String")!>x<!>
val z: String = <!DEBUG_INFO_SMARTCAST!>x<!>
}
}
@@ -1666,6 +1666,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/callableReference/classVsPackage.kt");
}
@TestMetadata("correctInfoAfterArrayLikeCall.kt")
public void testCorrectInfoAfterArrayLikeCall() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
}
@TestMetadata("ea81649_errorPropertyLHS.kt")
public void testEa81649_errorPropertyLHS() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/ea81649_errorPropertyLHS.kt");
@@ -1691,6 +1696,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/callableReference/kt25433.kt");
}
@TestMetadata("kt31981.kt")
public void testKt31981() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/kt31981.kt");
}
@TestMetadata("kt7430_wrongClassOnLHS.kt")
public void testKt7430_wrongClassOnLHS() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.kt");
@@ -1661,6 +1661,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/callableReference/classVsPackage.kt");
}
@TestMetadata("correctInfoAfterArrayLikeCall.kt")
public void testCorrectInfoAfterArrayLikeCall() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
}
@TestMetadata("ea81649_errorPropertyLHS.kt")
public void testEa81649_errorPropertyLHS() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/ea81649_errorPropertyLHS.kt");
@@ -1686,6 +1691,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/callableReference/kt25433.kt");
}
@TestMetadata("kt31981.kt")
public void testKt31981() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/kt31981.kt");
}
@TestMetadata("kt7430_wrongClassOnLHS.kt")
public void testKt7430_wrongClassOnLHS() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.kt");