From 685d16ec68e68c9a811d736350de22c5d594b58f Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Wed, 9 Sep 2020 11:55:18 +0300 Subject: [PATCH] NI: don't do substitution for unsupported callable descriptors to use as callable references ^KT-41729 Fixed --- ...irOldFrontendDiagnosticsTestGenerated.java | 53 +++++++++++++------ ...endDiagnosticsTestWithStdlibGenerated.java | 5 ++ .../calls/tower/ResolvedAtomCompleter.kt | 11 ++-- .../components/CallableReferenceResolution.kt | 11 ++-- .../callableReferenceToLocalVariable.fir.kt | 0 .../callableReferenceToLocalVariable.kt | 0 .../callableReferenceToLocalVariable.txt | 0 .../localVariable.fir.kt | 0 .../localVariable.kt | 0 .../localVariable.txt | 0 .../localVariableWithSubstitution.fir.kt | 14 +++++ .../localVariableWithSubstitution.kt | 14 +++++ .../localVariableWithSubstitution.txt | 11 ++++ .../parameterWithSubstitution.fir.kt | 14 +++++ .../unsupported/parameterWithSubstitution.kt | 14 +++++ .../unsupported/parameterWithSubstitution.txt | 11 ++++ .../syntheticProperties.fir.kt | 0 .../syntheticProperties.kt | 0 .../syntheticProperties.txt | 0 .../callableReferenceOnParameter.fir.kt | 8 +++ .../inference/callableReferenceOnParameter.kt | 8 +++ .../callableReferenceOnParameter.txt | 10 ++++ .../checkers/DiagnosticsTestGenerated.java | 53 +++++++++++++------ .../DiagnosticsTestWithStdLibGenerated.java | 5 ++ ...ticsTestWithStdLibUsingJavacGenerated.java | 5 ++ .../DiagnosticsUsingJavacTestGenerated.java | 53 +++++++++++++------ .../kotlin/descriptors/descriptorUtil.kt | 2 + 27 files changed, 247 insertions(+), 55 deletions(-) rename compiler/testData/diagnostics/tests/callableReference/{ => unsupported}/callableReferenceToLocalVariable.fir.kt (100%) rename compiler/testData/diagnostics/tests/callableReference/{ => unsupported}/callableReferenceToLocalVariable.kt (100%) rename compiler/testData/diagnostics/tests/callableReference/{ => unsupported}/callableReferenceToLocalVariable.txt (100%) rename compiler/testData/diagnostics/tests/callableReference/{property => unsupported}/localVariable.fir.kt (100%) rename compiler/testData/diagnostics/tests/callableReference/{property => unsupported}/localVariable.kt (100%) rename compiler/testData/diagnostics/tests/callableReference/{property => unsupported}/localVariable.txt (100%) create mode 100644 compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.txt rename compiler/testData/diagnostics/tests/callableReference/{property => unsupported}/syntheticProperties.fir.kt (100%) rename compiler/testData/diagnostics/tests/callableReference/{property => unsupported}/syntheticProperties.kt (100%) rename compiler/testData/diagnostics/tests/callableReference/{property => unsupported}/syntheticProperties.txt (100%) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.txt diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index fbf4c11121a..69670cda45a 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -1784,11 +1784,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceAsLastExpressionInBlock.kt"); } - @TestMetadata("callableReferenceToLocalVariable.kt") - public void testCallableReferenceToLocalVariable() throws Exception { - runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceToLocalVariable.kt"); - } - @TestMetadata("classVsPackage.kt") public void testClassVsPackage() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/classVsPackage.kt"); @@ -2555,11 +2550,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.kt"); } - @TestMetadata("localVariable.kt") - public void testLocalVariable() throws Exception { - runTest("compiler/testData/diagnostics/tests/callableReference/property/localVariable.kt"); - } - @TestMetadata("memberFromTopLevel.kt") public void testMemberFromTopLevel() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.kt"); @@ -2580,11 +2570,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/callableReference/property/samePriorityForFunctionsAndProperties.kt"); } - @TestMetadata("syntheticProperties.kt") - public void testSyntheticProperties() throws Exception { - runTest("compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.kt"); - } - @TestMetadata("topLevelFromTopLevel.kt") public void testTopLevelFromTopLevel() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/property/topLevelFromTopLevel.kt"); @@ -2853,6 +2838,44 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.kt"); } } + + @TestMetadata("compiler/testData/diagnostics/tests/callableReference/unsupported") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Unsupported extends AbstractFirOldFrontendDiagnosticsTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInUnsupported() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/unsupported"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("callableReferenceToLocalVariable.kt") + public void testCallableReferenceToLocalVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt"); + } + + @TestMetadata("localVariable.kt") + public void testLocalVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.kt"); + } + + @TestMetadata("localVariableWithSubstitution.kt") + public void testLocalVariableWithSubstitution() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.kt"); + } + + @TestMetadata("parameterWithSubstitution.kt") + public void testParameterWithSubstitution() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.kt"); + } + + @TestMetadata("syntheticProperties.kt") + public void testSyntheticProperties() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.kt"); + } + } } @TestMetadata("compiler/testData/diagnostics/tests/cast") diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java index 4fad49229c9..3da8d522e02 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java @@ -2908,6 +2908,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi runTest("compiler/testData/diagnostics/testsWithStdLib/inference/arrayConstructor.kt"); } + @TestMetadata("callableReferenceOnParameter.kt") + public void testCallableReferenceOnParameter() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.kt"); + } + @TestMetadata("integerLiterals.kt") public void testIntegerLiterals() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/inference/integerLiterals.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 87e3e873234..65c1254fb6f 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 @@ -345,12 +345,11 @@ class ResolvedAtomCompleter( (callableCandidate.candidate.typeParameters.map { it.typeConstructor } zip resultTypeParameters).toMap() ) - val firstSubstitution = typeParametersSubstitutor.toOldSubstitution() - val secondSubstitution = resultSubstitutor.toOldSubstitution() - val resultSubstitutor = TypeSubstitutor.createChainedSubstitutor( - firstSubstitution, - secondSubstitution - ) + val resultSubstitutor = if (callableCandidate.candidate.isSupportedForCallableReference()) { + val firstSubstitution = typeParametersSubstitutor.toOldSubstitution() + val secondSubstitution = resultSubstitutor.toOldSubstitution() + TypeSubstitutor.createChainedSubstitutor(firstSubstitution, secondSubstitution) + } else TypeSubstitutor.EMPTY val psiCallArgument = resolvedAtom.atom.psiCallArgument as CallableReferenceKotlinCallArgumentImpl val callableReferenceExpression = psiCallArgument.ktCallableReferenceExpression diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt index 2cc77c6d7a0..b455fd75f9c 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt @@ -491,7 +491,7 @@ class CallableReferencesCandidateFactory( val descriptorReturnType = descriptor.returnType ?: ErrorUtils.createErrorType("Error return type for descriptor: $descriptor") - when (descriptor) { + return when (descriptor) { is PropertyDescriptor -> { val mutable = descriptor.isVar && run { val setter = descriptor.setter @@ -501,7 +501,7 @@ class CallableReferencesCandidateFactory( ) } - return callComponents.reflectionTypes.getKPropertyType( + callComponents.reflectionTypes.getKPropertyType( Annotations.EMPTY, argumentsAndReceivers, descriptorReturnType, @@ -532,12 +532,15 @@ class CallableReferencesCandidateFactory( val suspendConversionStrategy = callableReferenceAdaptation?.suspendConversionStrategy val isSuspend = descriptor.isSuspend || suspendConversionStrategy == SuspendConversionStrategy.SUSPEND_CONVERSION - return callComponents.reflectionTypes.getKFunctionType( + callComponents.reflectionTypes.getKFunctionType( Annotations.EMPTY, null, argumentsAndReceivers, null, returnType, descriptor.builtIns, isSuspend ) to callableReferenceAdaptation } - else -> return ErrorUtils.createErrorType("Unsupported descriptor type: $descriptor") to null + else -> { + assert(!descriptor.isSupportedForCallableReference()) { "${descriptor::class} isn't supported to use in callable references actually, but it's listed in `isSupportedForCallableReference` method" } + ErrorUtils.createErrorType("Unsupported descriptor type: $descriptor") to null + } } } diff --git a/compiler/testData/diagnostics/tests/callableReference/callableReferenceToLocalVariable.fir.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.fir.kt similarity index 100% rename from compiler/testData/diagnostics/tests/callableReference/callableReferenceToLocalVariable.fir.kt rename to compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.fir.kt diff --git a/compiler/testData/diagnostics/tests/callableReference/callableReferenceToLocalVariable.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt similarity index 100% rename from compiler/testData/diagnostics/tests/callableReference/callableReferenceToLocalVariable.kt rename to compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt diff --git a/compiler/testData/diagnostics/tests/callableReference/callableReferenceToLocalVariable.txt b/compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.txt similarity index 100% rename from compiler/testData/diagnostics/tests/callableReference/callableReferenceToLocalVariable.txt rename to compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.txt diff --git a/compiler/testData/diagnostics/tests/callableReference/property/localVariable.fir.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.fir.kt similarity index 100% rename from compiler/testData/diagnostics/tests/callableReference/property/localVariable.fir.kt rename to compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.fir.kt diff --git a/compiler/testData/diagnostics/tests/callableReference/property/localVariable.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.kt similarity index 100% rename from compiler/testData/diagnostics/tests/callableReference/property/localVariable.kt rename to compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.kt diff --git a/compiler/testData/diagnostics/tests/callableReference/property/localVariable.txt b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.txt similarity index 100% rename from compiler/testData/diagnostics/tests/callableReference/property/localVariable.txt rename to compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.txt diff --git a/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.fir.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.fir.kt new file mode 100644 index 00000000000..507c335add4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.fir.kt @@ -0,0 +1,14 @@ +// Issue: KT-41729 + +import kotlin.reflect.KProperty + +class Foo { + operator fun getValue(thisRef: Any?, property: KProperty<*>) = 1 +} + +fun main() { + val f = Foo() + val a: Int + get() = f.getValue(null, ::a) // no exception after fix + print(a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.kt new file mode 100644 index 00000000000..401b1b31817 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.kt @@ -0,0 +1,14 @@ +// Issue: KT-41729 + +import kotlin.reflect.KProperty + +class Foo { + operator fun getValue(thisRef: Any?, property: KProperty<*>) = 1 +} + +fun main() { + val f = Foo() + val a: Int + get() = f.getValue(null, ::a) // no exception after fix + print(a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.txt b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.txt new file mode 100644 index 00000000000..a75f18fc692 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.txt @@ -0,0 +1,11 @@ +package + +public fun main(): kotlin.Unit + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final operator fun getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): 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/unsupported/parameterWithSubstitution.fir.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.fir.kt new file mode 100644 index 00000000000..bb4e8214385 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.fir.kt @@ -0,0 +1,14 @@ +// Issue: KT-41729 + +import kotlin.reflect.KProperty + +class Foo { + operator fun getValue(thisRef: Any?, property: KProperty<*>) = 1 +} + +fun main(x: Int) { + val f = Foo() + val a: Int + get() = f.getValue(null, ::x) // no exception after fix + print(a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.kt new file mode 100644 index 00000000000..334f29d9a76 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.kt @@ -0,0 +1,14 @@ +// Issue: KT-41729 + +import kotlin.reflect.KProperty + +class Foo { + operator fun getValue(thisRef: Any?, property: KProperty<*>) = 1 +} + +fun main(x: Int) { + val f = Foo() + val a: Int + get() = f.getValue(null, ::x) // no exception after fix + print(a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.txt b/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.txt new file mode 100644 index 00000000000..0de0dc91981 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.txt @@ -0,0 +1,11 @@ +package + +public fun main(/*0*/ x: kotlin.Int): kotlin.Unit + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final operator fun getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): 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/property/syntheticProperties.fir.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.fir.kt similarity index 100% rename from compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.fir.kt rename to compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.fir.kt diff --git a/compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.kt similarity index 100% rename from compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.kt rename to compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.kt diff --git a/compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.txt b/compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.txt similarity index 100% rename from compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.txt rename to compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.txt diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.fir.kt new file mode 100644 index 00000000000..7c6252e64c1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.fir.kt @@ -0,0 +1,8 @@ +// Issue: KT-37736 + +internal class Z { + val map = HashMap() + inline fun compute(key: String, producer: () -> String): String { + return map.getOrPut(key, ::producer) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.kt new file mode 100644 index 00000000000..ae0f37a8578 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.kt @@ -0,0 +1,8 @@ +// Issue: KT-37736 + +internal class Z { + val map = HashMap() + inline fun compute(key: String, producer: () -> String): String { + return map.getOrPut(key, ::producer) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.txt new file mode 100644 index 00000000000..1b585c83866 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.txt @@ -0,0 +1,10 @@ +package + +internal final class Z { + public constructor Z() + public final val map: kotlin.collections.HashMap /* = java.util.HashMap */ + public final inline fun compute(/*0*/ key: kotlin.String, /*1*/ producer: () -> kotlin.String): kotlin.String + 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/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 123e845722f..244595fe1c9 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -1791,11 +1791,6 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceAsLastExpressionInBlock.kt"); } - @TestMetadata("callableReferenceToLocalVariable.kt") - public void testCallableReferenceToLocalVariable() throws Exception { - runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceToLocalVariable.kt"); - } - @TestMetadata("classVsPackage.kt") public void testClassVsPackage() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/classVsPackage.kt"); @@ -2562,11 +2557,6 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.kt"); } - @TestMetadata("localVariable.kt") - public void testLocalVariable() throws Exception { - runTest("compiler/testData/diagnostics/tests/callableReference/property/localVariable.kt"); - } - @TestMetadata("memberFromTopLevel.kt") public void testMemberFromTopLevel() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.kt"); @@ -2587,11 +2577,6 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/callableReference/property/samePriorityForFunctionsAndProperties.kt"); } - @TestMetadata("syntheticProperties.kt") - public void testSyntheticProperties() throws Exception { - runTest("compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.kt"); - } - @TestMetadata("topLevelFromTopLevel.kt") public void testTopLevelFromTopLevel() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/property/topLevelFromTopLevel.kt"); @@ -2860,6 +2845,44 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.kt"); } } + + @TestMetadata("compiler/testData/diagnostics/tests/callableReference/unsupported") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Unsupported extends AbstractDiagnosticsTestWithFirValidation { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInUnsupported() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/unsupported"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("callableReferenceToLocalVariable.kt") + public void testCallableReferenceToLocalVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt"); + } + + @TestMetadata("localVariable.kt") + public void testLocalVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.kt"); + } + + @TestMetadata("localVariableWithSubstitution.kt") + public void testLocalVariableWithSubstitution() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.kt"); + } + + @TestMetadata("parameterWithSubstitution.kt") + public void testParameterWithSubstitution() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.kt"); + } + + @TestMetadata("syntheticProperties.kt") + public void testSyntheticProperties() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.kt"); + } + } } @TestMetadata("compiler/testData/diagnostics/tests/cast") diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index e4530487dae..b47a2f8e7dc 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -3058,6 +3058,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/inference/arrayConstructor.kt"); } + @TestMetadata("callableReferenceOnParameter.kt") + public void testCallableReferenceOnParameter() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.kt"); + } + @TestMetadata("integerLiterals.kt") public void testIntegerLiterals() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/inference/integerLiterals.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index 1abe51c80ad..959bc11f620 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -3058,6 +3058,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/inference/arrayConstructor.kt"); } + @TestMetadata("callableReferenceOnParameter.kt") + public void testCallableReferenceOnParameter() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.kt"); + } + @TestMetadata("integerLiterals.kt") public void testIntegerLiterals() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/inference/integerLiterals.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index f4d086bd377..a5fa5b1090e 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -1786,11 +1786,6 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceAsLastExpressionInBlock.kt"); } - @TestMetadata("callableReferenceToLocalVariable.kt") - public void testCallableReferenceToLocalVariable() throws Exception { - runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceToLocalVariable.kt"); - } - @TestMetadata("classVsPackage.kt") public void testClassVsPackage() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/classVsPackage.kt"); @@ -2557,11 +2552,6 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/callableReference/property/kt7945_unrelatedClass.kt"); } - @TestMetadata("localVariable.kt") - public void testLocalVariable() throws Exception { - runTest("compiler/testData/diagnostics/tests/callableReference/property/localVariable.kt"); - } - @TestMetadata("memberFromTopLevel.kt") public void testMemberFromTopLevel() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/property/memberFromTopLevel.kt"); @@ -2582,11 +2572,6 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/callableReference/property/samePriorityForFunctionsAndProperties.kt"); } - @TestMetadata("syntheticProperties.kt") - public void testSyntheticProperties() throws Exception { - runTest("compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.kt"); - } - @TestMetadata("topLevelFromTopLevel.kt") public void testTopLevelFromTopLevel() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/property/topLevelFromTopLevel.kt"); @@ -2855,6 +2840,44 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.kt"); } } + + @TestMetadata("compiler/testData/diagnostics/tests/callableReference/unsupported") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Unsupported extends AbstractDiagnosticsUsingJavacTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInUnsupported() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/unsupported"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("callableReferenceToLocalVariable.kt") + public void testCallableReferenceToLocalVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt"); + } + + @TestMetadata("localVariable.kt") + public void testLocalVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.kt"); + } + + @TestMetadata("localVariableWithSubstitution.kt") + public void testLocalVariableWithSubstitution() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.kt"); + } + + @TestMetadata("parameterWithSubstitution.kt") + public void testParameterWithSubstitution() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.kt"); + } + + @TestMetadata("syntheticProperties.kt") + public void testSyntheticProperties() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/unsupported/syntheticProperties.kt"); + } + } } @TestMetadata("compiler/testData/diagnostics/tests/cast") diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/descriptorUtil.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/descriptorUtil.kt index bbbbc99f3d4..f70c0276280 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/descriptorUtil.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/descriptorUtil.kt @@ -54,3 +54,5 @@ fun DeclarationDescriptor.isTopLevelInPackage(name: String, packageName: String) val packageFqName = containingDeclaration.fqName.asString() return packageName == packageFqName } + +fun CallableDescriptor.isSupportedForCallableReference() = this is PropertyDescriptor || this is FunctionDescriptor