From 2877314313507889ead0c01132e091aba0c95106 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 24 Aug 2017 17:15:42 +0300 Subject: [PATCH] Support "::foo" as a short-hand for "this::foo" #KT-15667 Fixed --- .../jetbrains/kotlin/diagnostics/Errors.java | 1 - .../rendering/DefaultErrorMessages.java | 3 - .../DoubleColonExpressionResolver.kt | 10 +++- .../box/callableReference/bound/emptyLHS.kt | 58 +++++++++++++++++++ .../tests/callableReference/emptyLhs.kt | 17 +++--- .../function/innerConstructorFromClass.kt | 4 +- .../function/innerConstructorFromExtension.kt | 4 +- .../function/noAmbiguityMemberVsTopLevel.kt | 23 +++++--- .../function/noAmbiguityMemberVsTopLevel.txt | 8 ++- .../noCallableReferencesWithEmptyLHS.kt | 28 +++++++++ .../noCallableReferencesWithEmptyLHS.txt | 24 ++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 ++ .../checkers/DiagnosticsTestGenerated.java | 6 ++ .../DiagnosticsUsingJavacTestGenerated.java | 6 ++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++ .../LightAnalysisModeTestGenerated.java | 6 ++ .../kotlin/config/LanguageVersionSettings.kt | 1 + .../inspections/KotlinCleanupInspection.kt | 1 - .../AddTypeToLHSOfCallableReferenceFix.kt | 54 ----------------- .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 2 - .../addTypeToLHSOfCallableReference/member.kt | 8 --- .../member.kt.after | 8 --- .../idea/quickfix/QuickFixTestGenerated.java | 15 ----- .../semantics/JsCodegenBoxTestGenerated.java | 12 ++++ 24 files changed, 195 insertions(+), 116 deletions(-) create mode 100644 compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.kt create mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.txt delete mode 100644 idea/src/org/jetbrains/kotlin/idea/quickfix/AddTypeToLHSOfCallableReferenceFix.kt delete mode 100644 idea/testData/quickfix/migration/addTypeToLHSOfCallableReference/member.kt delete mode 100644 idea/testData/quickfix/migration/addTypeToLHSOfCallableReference/member.kt.after diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index aea058aaa43..930d31ef47d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -659,7 +659,6 @@ public interface Errors { DiagnosticFactory1 EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED = DiagnosticFactory1.create(ERROR); DiagnosticFactory0 CALLABLE_REFERENCE_LHS_NOT_A_CLASS = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 CLASS_LITERAL_LHS_NOT_A_CLASS = DiagnosticFactory0.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index f5bff4c1c3f..84ad5adb401 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -839,9 +839,6 @@ public class DefaultErrorMessages { MAP.put(EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED, "''{0}'' is a member and an extension at the same time. References to such elements are not allowed", NAME); MAP.put(CALLABLE_REFERENCE_LHS_NOT_A_CLASS, "Left-hand side of a callable reference cannot be a type parameter"); - MAP.put(CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS, - "Left-hand side of a callable reference with a receiver parameter cannot be empty. " + - "Please specify the type of the receiver before '::' explicitly"); MAP.put(CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR, "Annotation class cannot be instantiated"); MAP.put(CLASS_LITERAL_LHS_NOT_A_CLASS, "Only classes are allowed on the left hand side of a class literal"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt index 43628f02ac4..a794b4e57af 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt @@ -550,9 +550,13 @@ class DoubleColonExpressionResolver( descriptor: CallableDescriptor, trace: BindingTrace, expression: KtCallableReferenceExpression ) { val simpleName = expression.callableReference - if (expression.isEmptyLHS && - (descriptor.dispatchReceiverParameter != null || descriptor.extensionReceiverParameter != null)) { - trace.report(CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS.on(simpleName)) + if (!languageVersionSettings.supportsFeature(LanguageFeature.CallableReferencesToClassMembersWithEmptyLHS)) { + if (expression.isEmptyLHS && + (descriptor.dispatchReceiverParameter != null || descriptor.extensionReceiverParameter != null)) { + trace.report(UNSUPPORTED_FEATURE.on( + simpleName, LanguageFeature.CallableReferencesToClassMembersWithEmptyLHS to languageVersionSettings + )) + } } if (descriptor is ConstructorDescriptor && DescriptorUtils.isAnnotationClass(descriptor.containingDeclaration)) { trace.report(CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR.on(simpleName)) diff --git a/compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt b/compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt new file mode 100644 index 00000000000..dacc29ef85f --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt @@ -0,0 +1,58 @@ +// IGNORE_BACKEND: JS +// LANGUAGE_VERSION: 1.2 + +var result = "" + +class A { + fun memberFunction() { result += "A.mf," } + fun aMemberFunction() { result += "A.amf," } + val memberProperty: Int get() = 42.also { result += "A.mp," } + val aMemberProperty: Int get() = 42.also { result += "A.amp," } + + fun test(): String { + (::memberFunction)() + (::aExtensionFunction)() + + (::memberProperty)() + (::aExtensionProperty)() + + return result + } + + inner class B { + fun memberFunction() { result += "B.mf," } + val memberProperty: Int get() = 42.also { result += "B.mp," } + + fun test(): String { + (::aMemberFunction)() + (::aExtensionFunction)() + + (::aMemberProperty)() + (::aExtensionProperty)() + + (::memberFunction)() + (::memberProperty)() + + (::bExtensionFunction)() + (::bExtensionProperty)() + + return result + } + } +} + +fun A.aExtensionFunction() { result += "A.ef," } +val A.aExtensionProperty: Int get() = 42.also { result += "A.ep," } +fun A.B.bExtensionFunction() { result += "B.ef," } +val A.B.bExtensionProperty: Int get() = 42.also { result += "B.ep," } + +fun box(): String { + val a = A().test() + if (a != "A.mf,A.ef,A.mp,A.ep,") return "Fail $a" + + result = "" + val b = A().B().test() + if (b != "A.amf,A.ef,A.amp,A.ep,B.mf,B.mp,B.ef,B.ep,") return "Fail $b" + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/callableReference/emptyLhs.kt b/compiler/testData/diagnostics/tests/callableReference/emptyLhs.kt index 7a22a2cd1b9..cf009c8a4fe 100644 --- a/compiler/testData/diagnostics/tests/callableReference/emptyLhs.kt +++ b/compiler/testData/diagnostics/tests/callableReference/emptyLhs.kt @@ -1,4 +1,5 @@ // !DIAGNOSTICS: -UNUSED_EXPRESSION, -EXTENSION_SHADOWED_BY_MEMBER +// !LANGUAGE: +CallableReferencesToClassMembersWithEmptyLHS val topLevelVal = 1 fun topLevelFun() = 2 @@ -14,13 +15,13 @@ class A { val ok2 = ::topLevelFun fun fail1() { - ::extensionVal - ::extensionFun + ::extensionVal + ::extensionFun } fun fail2() { - ::memberVal - ::memberFun + ::memberVal + ::memberFun } } @@ -30,11 +31,11 @@ val ok1 = ::topLevelVal val ok2 = ::topLevelFun fun A.fail1() { - ::extensionVal - ::extensionFun + ::extensionVal + ::extensionFun } fun A.fail2() { - ::memberVal - ::memberFun + ::memberVal + ::memberFun } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt index 6fa5e6c14eb..a2ddb0d2c4a 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromClass.kt @@ -1,12 +1,14 @@ // !CHECK_TYPE // !DIAGNOSTICS: -UNUSED_EXPRESSION +// !LANGUAGE: +CallableReferencesToClassMembersWithEmptyLHS + import kotlin.reflect.KFunction1 class A { inner class Inner fun main() { - ::Inner + ::Inner val y = A::Inner checkSubtype>(y) diff --git a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.kt b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.kt index 74c6dbbd2b5..90c304bd862 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/innerConstructorFromExtension.kt @@ -1,5 +1,7 @@ // !CHECK_TYPE // !DIAGNOSTICS: -UNUSED_EXPRESSION +// !LANGUAGE: +CallableReferencesToClassMembersWithEmptyLHS + import kotlin.reflect.KFunction1 class A { @@ -7,7 +9,7 @@ class A { } fun A.main() { - ::Inner + ::Inner val y = A::Inner checkSubtype>(y) diff --git a/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.kt b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.kt index fd68f9f7f28..8d1f5558aa6 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.kt @@ -1,24 +1,31 @@ // !CHECK_TYPE +// !LANGUAGE: +CallableReferencesToClassMembersWithEmptyLHS import kotlin.reflect.KFunction0 -fun explicitlyExpectFunction0(f: () -> Unit) = f -fun explicitlyExpectFunction1(f: (A) -> Unit) = f +fun expectFunction0Unit(f: () -> Unit) = f +fun expectFunction0String(f: () -> String) = f +fun expectFunction1Unit(f: (A) -> Unit) = f +fun expectFunction1String(f: (A) -> String) = f -fun foo() {} +fun foo(): String = "" class A { fun foo() {} fun main() { - val x = ::foo + val x = ::foo checkSubtype>(x) - explicitlyExpectFunction0(x) - explicitlyExpectFunction1(x) + expectFunction0Unit(x) + expectFunction0String(x) + expectFunction1Unit(x) + expectFunction1String(x) - explicitlyExpectFunction0(::foo) - explicitlyExpectFunction1(::foo) + expectFunction0Unit(::foo) + expectFunction0String(::foo) + expectFunction1Unit(::foo) + expectFunction1String(::foo) } } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.txt b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.txt index a3758aeff4a..b587c290015 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.txt +++ b/compiler/testData/diagnostics/tests/callableReference/function/noAmbiguityMemberVsTopLevel.txt @@ -1,8 +1,10 @@ package -public fun explicitlyExpectFunction0(/*0*/ f: () -> kotlin.Unit): () -> kotlin.Unit -public fun explicitlyExpectFunction1(/*0*/ f: (A) -> kotlin.Unit): (A) -> kotlin.Unit -public fun foo(): kotlin.Unit +public fun expectFunction0String(/*0*/ f: () -> kotlin.String): () -> kotlin.String +public fun expectFunction0Unit(/*0*/ f: () -> kotlin.Unit): () -> kotlin.Unit +public fun expectFunction1String(/*0*/ f: (A) -> kotlin.String): (A) -> kotlin.String +public fun expectFunction1Unit(/*0*/ f: (A) -> kotlin.Unit): (A) -> kotlin.Unit +public fun foo(): kotlin.String public final class A { public constructor A() diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.kt new file mode 100644 index 00000000000..4f66cb839f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.kt @@ -0,0 +1,28 @@ +// !LANGUAGE: -CallableReferencesToClassMembersWithEmptyLHS + +class A { + fun memberFunction() {} + val memberProperty: Int get() = 42 + + fun test() { + (::memberFunction)() + (::extensionFunction)() + (::memberProperty)() + (::extensionProperty)() + } + + inner class B { + fun memberFunction() { } + val memberProperty: Int get() = 43 + + fun test() { + (::memberFunction)() + (::extensionFunction)() + (::memberProperty)() + (::extensionProperty)() + } + } +} + +fun A.extensionFunction() {} +val A.extensionProperty: Int get() = 44 diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.txt b/compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.txt new file mode 100644 index 00000000000..79efa06a799 --- /dev/null +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.txt @@ -0,0 +1,24 @@ +package + +public val A.extensionProperty: kotlin.Int +public fun A.extensionFunction(): kotlin.Unit + +public final class A { + public constructor A() + public final val memberProperty: kotlin.Int + 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 final fun memberFunction(): kotlin.Unit + public final fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final inner class B { + public constructor B() + public final val memberProperty: kotlin.Int + 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 final fun memberFunction(): kotlin.Unit + public final fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 02679fe72e5..c9ef831a33f 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -1669,6 +1669,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("emptyLHS.kt") + public void testEmptyLHS() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt"); + doTest(fileName); + } + @TestMetadata("enumEntryMember.kt") public void testEnumEntryMember() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/enumEntryMember.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index a527802d278..cd6c1ed59ba 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -21877,6 +21877,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("noCallableReferencesWithEmptyLHS.kt") + public void testNoCallableReferencesWithEmptyLHS() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.kt"); + doTest(fileName); + } + @TestMetadata("noDataClassInheritance.kt") public void testNoDataClassInheritance() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/sourceCompatibility/noDataClassInheritance.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 62789ddec91..15845d28be7 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -21877,6 +21877,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing doTest(fileName); } + @TestMetadata("noCallableReferencesWithEmptyLHS.kt") + public void testNoCallableReferencesWithEmptyLHS() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/sourceCompatibility/noCallableReferencesWithEmptyLHS.kt"); + doTest(fileName); + } + @TestMetadata("noDataClassInheritance.kt") public void testNoDataClassInheritance() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/sourceCompatibility/noDataClassInheritance.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index f95670eb0a8..c4fc1659f26 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -1669,6 +1669,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("emptyLHS.kt") + public void testEmptyLHS() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt"); + doTest(fileName); + } + @TestMetadata("enumEntryMember.kt") public void testEnumEntryMember() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/enumEntryMember.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 4cfc3e719fd..44f6d69890c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -1669,6 +1669,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("emptyLHS.kt") + public void testEmptyLHS() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt"); + doTest(fileName); + } + @TestMetadata("enumEntryMember.kt") public void testEnumEntryMember() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/enumEntryMember.kt"); diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index e9b1c8a9fba..a8c3a74a9d2 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -59,6 +59,7 @@ enum class LanguageFeature( CapturedInClosureSmartCasts(KOTLIN_1_2), LateinitTopLevelProperties(KOTLIN_1_2), LateinitLocalVariables(KOTLIN_1_2), + CallableReferencesToClassMembersWithEmptyLHS(KOTLIN_1_2), RestrictionOfValReassignmentViaBackingField(KOTLIN_1_3), diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt index d372165e5e5..d0969df3e18 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt @@ -94,7 +94,6 @@ class KotlinCleanupInspection : LocalInspectionTool(), CleanupLocalInspectionToo Errors.NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION, Errors.OPERATOR_MODIFIER_REQUIRED, Errors.INFIX_MODIFIER_REQUIRED, - Errors.CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS, Errors.DEPRECATED_TYPE_PARAMETER_SYNTAX, Errors.MISPLACED_TYPE_PARAMETER_CONSTRAINTS, Errors.COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT, diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddTypeToLHSOfCallableReferenceFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddTypeToLHSOfCallableReferenceFix.kt deleted file mode 100644 index b898ccc67d0..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddTypeToLHSOfCallableReferenceFix.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.quickfix - -import com.intellij.codeInsight.intention.IntentionAction -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.project.Project -import org.jetbrains.kotlin.diagnostics.Diagnostic -import org.jetbrains.kotlin.idea.caches.resolve.analyze -import org.jetbrains.kotlin.idea.core.ShortenReferences -import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers -import org.jetbrains.kotlin.psi.KtCallableReferenceExpression -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.psi.KtPsiFactory -import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall -import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode - -class AddTypeToLHSOfCallableReferenceFix( - expression: KtCallableReferenceExpression -) : KotlinQuickFixAction(expression), CleanupFix { - override fun getFamilyName() = "Add type to left-hand side" - override fun getText() = familyName - - override fun invoke(project: Project, editor: Editor?, file: KtFile) { - val element = element ?: return - val resolvedCall = element.callableReference.getResolvedCall(element.analyze(BodyResolveMode.PARTIAL)) ?: return - val receiver = with(resolvedCall) { - dispatchReceiver ?: extensionReceiver ?: return - } - val expression = KtPsiFactory(project).createExpression(IdeDescriptorRenderers.SOURCE_CODE.renderType(receiver.type)) - element.setReceiverExpression(expression) - ShortenReferences.DEFAULT.process(element) - } - - companion object : KotlinSingleIntentionActionFactory() { - override fun createAction(diagnostic: Diagnostic): IntentionAction? { - return AddTypeToLHSOfCallableReferenceFix(diagnostic.psiElement.parent as KtCallableReferenceExpression) - } - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index ec5106bef1d..bda9125cff0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -421,8 +421,6 @@ class QuickFixRegistrar : QuickFixContributor { UNDERSCORE_IS_RESERVED.registerFactory(RenameUnderscoreFix) - CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS.registerFactory(AddTypeToLHSOfCallableReferenceFix) - DEPRECATED_TYPE_PARAMETER_SYNTAX.registerFactory(MigrateTypeParameterListFix) UNRESOLVED_REFERENCE.registerFactory(KotlinAddOrderEntryActionFactory) diff --git a/idea/testData/quickfix/migration/addTypeToLHSOfCallableReference/member.kt b/idea/testData/quickfix/migration/addTypeToLHSOfCallableReference/member.kt deleted file mode 100644 index 439dc647908..00000000000 --- a/idea/testData/quickfix/migration/addTypeToLHSOfCallableReference/member.kt +++ /dev/null @@ -1,8 +0,0 @@ -// "Add type to left-hand side" "true" -package foo.bar - -class A { - fun foo() {} - - fun bar() = ::foo -} diff --git a/idea/testData/quickfix/migration/addTypeToLHSOfCallableReference/member.kt.after b/idea/testData/quickfix/migration/addTypeToLHSOfCallableReference/member.kt.after deleted file mode 100644 index d67915b2876..00000000000 --- a/idea/testData/quickfix/migration/addTypeToLHSOfCallableReference/member.kt.after +++ /dev/null @@ -1,8 +0,0 @@ -// "Add type to left-hand side" "true" -package foo.bar - -class A { - fun foo() {} - - fun bar() = A::foo -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index d9c943bee4d..89740fe89bc 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -6764,21 +6764,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); } - @TestMetadata("idea/testData/quickfix/migration/addTypeToLHSOfCallableReference") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class AddTypeToLHSOfCallableReference extends AbstractQuickFixTest { - public void testAllFilesPresentInAddTypeToLHSOfCallableReference() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration/addTypeToLHSOfCallableReference"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("member.kt") - public void testMember() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/addTypeToLHSOfCallableReference/member.kt"); - doTest(fileName); - } - } - @TestMetadata("idea/testData/quickfix/migration/commasInWhenWithoutArgument") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 265d834b6f4..95f05b64b63 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -1957,6 +1957,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("emptyLHS.kt") + public void testEmptyLHS() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + @TestMetadata("enumEntryMember.kt") public void testEnumEntryMember() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/enumEntryMember.kt");