From 8fe632f52b85be035bb27700a4a215f0576ffd59 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 17 Jun 2019 16:40:50 +0300 Subject: [PATCH] [NI] Record DFI for callable reference arguments #KT-31941 Fixed --- .../fir/FirDiagnosticsSmokeTestGenerated.java | 10 +++++++ .../calls/tower/ResolvedAtomCompleter.kt | 4 ++- .../correctInfoAfterArrayLikeCall.kt | 16 ++++++++++++ .../correctInfoAfterArrayLikeCall.txt | 12 +++++++++ .../tests/callableReference/kt31981.kt | 23 ++++++++++++++++ .../tests/callableReference/kt31981.txt | 22 ++++++++++++++++ .../diagnostics/notLinked/dfa/pos/57.kt | 26 +++++++++---------- .../checkers/DiagnosticsTestGenerated.java | 10 +++++++ .../DiagnosticsUsingJavacTestGenerated.java | 10 +++++++ 9 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/kt31981.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/kt31981.txt diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java index 72a4846c51a..54e8d2c7b61 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java @@ -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"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt index 2750f5d521c..59a7748e9a9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.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( diff --git a/compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt b/compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt new file mode 100644 index 00000000000..00a027a90c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt @@ -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) { + intDTO[DTO::q] + intDTO.q + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.txt b/compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.txt new file mode 100644 index 00000000000..ad0189d423f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.txt @@ -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 +} diff --git a/compiler/testData/diagnostics/tests/callableReference/kt31981.kt b/compiler/testData/diagnostics/tests/callableReference/kt31981.kt new file mode 100644 index 00000000000..2ba8d91d33b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt31981.kt @@ -0,0 +1,23 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KProperty1 +import kotlin.reflect.KMutableProperty1 + +class Inv { + val size: Int = 0 +} + +class DTO { + val test: Inv? = null + var q: Int = 0 + operator fun get(prop: KProperty1<*, R>): R = TODO() + operator fun set(prop: KMutableProperty1<*, R>, value: R) { } +} + +fun main(intDTO: DTO?) { + if (intDTO != null) { + intDTO[DTO::q] = intDTO[DTO::test]!!.size + intDTO[DTO::q] = intDTO[DTO::test]!!.size + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/kt31981.txt b/compiler/testData/diagnostics/tests/callableReference/kt31981.txt new file mode 100644 index 00000000000..6173be9ae25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt31981.txt @@ -0,0 +1,22 @@ +package + +public fun main(/*0*/ intDTO: DTO?): kotlin.Unit + +public final class DTO { + public constructor DTO() + public final var q: kotlin.Int + public final val test: Inv? = null + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final operator fun get(/*0*/ prop: kotlin.reflect.KProperty1<*, R>): R + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final operator fun 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 { + public constructor Inv() + 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 +} diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/57.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/57.kt index e7305401a1e..24bb74cb491 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/57.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/57.kt @@ -20,8 +20,8 @@ fun case_1(x: Any?) { if (x is String) { x val y = if (true) Class::fun_1 else Class::fun_1 - x - val z: String = x + x + val z: String = x } } @@ -38,8 +38,8 @@ fun case_2(x: Any?, b: Boolean?) { false -> Class::fun_2 null -> Class::fun_3 } - x - val z: Any = x + x + val z: Any = x } /* @@ -53,8 +53,8 @@ fun case_3(x: Any?, b: Boolean?) { val y = when (b) { else -> Class::fun_1 } - x - val z: Int = x + x + val z: Int = x } // TESTCASE NUMBER: 4 @@ -77,8 +77,8 @@ fun case_5(x: Any?, b: Class) { x as Int x val y = if (true) b::fun_1 else b::fun_1 - x - val z: Int = x + x + val z: Int = x } /* @@ -91,9 +91,9 @@ fun case_6(x: Any?, b: Class) { val z1 = x x val y = if (true) b::fun_1 else b::fun_1 - x - z1 - val z2: Int = z1 + x + z1 + val z2: Int = z1 } /* @@ -106,8 +106,8 @@ fun case_7(x: Any?) { if (x is String) { x val y = if (true) ::case_7_1 else ::case_7_1 - x - val z: String = x + x + val z: String = x } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index bf1938640f4..6aceeed0fcd 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 4039be19101..85487291425 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -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");