Deprecate (V)::a reference resolution to companion in FE 1.0
^KT-45315 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
46b297477c
commit
7645663d12
+1
-1
@@ -358,5 +358,5 @@ object JvmRuntimeVersionsConsistencyChecker {
|
||||
}
|
||||
|
||||
private fun Manifest.getKotlinLanguageVersion(): MavenComparableVersion =
|
||||
(mainAttributes.getValue(KOTLIN_VERSION_ATTRIBUTE)?.let((ApiVersion)::parse) ?: ApiVersion.KOTLIN_1_0).version
|
||||
(mainAttributes.getValue(KOTLIN_VERSION_ATTRIBUTE)?.let(ApiVersion.Companion::parse) ?: ApiVersion.KOTLIN_1_0).version
|
||||
}
|
||||
|
||||
+6
@@ -2231,6 +2231,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("deprecatedCompanionReceiverInParentheses.kt")
|
||||
public void testDeprecatedCompanionReceiverInParentheses() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/deprecatedCompanionReceiverInParentheses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ea81649_errorPropertyLHS.kt")
|
||||
public void testEa81649_errorPropertyLHS() throws Exception {
|
||||
|
||||
+6
@@ -2231,6 +2231,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("deprecatedCompanionReceiverInParentheses.kt")
|
||||
public void testDeprecatedCompanionReceiverInParentheses() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/deprecatedCompanionReceiverInParentheses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ea81649_errorPropertyLHS.kt")
|
||||
public void testEa81649_errorPropertyLHS() throws Exception {
|
||||
|
||||
+1
-1
@@ -57,6 +57,6 @@ class IncrementalPackagePartProvider(
|
||||
}
|
||||
|
||||
override fun getAllOptionalAnnotationClasses(): List<ClassData> =
|
||||
moduleMappings.flatMap((JvmPackagePartProviderBase)::getAllOptionalAnnotationClasses) +
|
||||
moduleMappings.flatMap(JvmPackagePartProviderBase.Companion::getAllOptionalAnnotationClasses) +
|
||||
parent.getAllOptionalAnnotationClasses()
|
||||
}
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ class AnnotationSplitter(
|
||||
val (targeted, other) = this@AnnotationSplitter.splitAnnotations()
|
||||
|
||||
if (target != null) {
|
||||
targeted[target]?.let((Annotations)::create) ?: Annotations.EMPTY
|
||||
targeted[target]?.let(Annotations.Companion::create) ?: Annotations.EMPTY
|
||||
} else {
|
||||
other
|
||||
}
|
||||
|
||||
@@ -806,6 +806,8 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory0<KtExpression> RESERVED_SYNTAX_IN_CALLABLE_REFERENCE_LHS = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtParenthesizedExpression> PARENTHESIZED_COMPANION_LHS_DEPRECATION = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
// Type inference
|
||||
|
||||
DiagnosticFactory0<KtParameter> CANNOT_INFER_PARAMETER_TYPE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
+2
@@ -444,6 +444,8 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(RESERVED_SYNTAX_IN_CALLABLE_REFERENCE_LHS, "Left-hand side of callable reference matches expression syntax reserved for future releases");
|
||||
|
||||
MAP.put(PARENTHESIZED_COMPANION_LHS_DEPRECATION, "Access to companion object through parenthesized class name is deprecated. Please, add explicit Companion qualifier.");
|
||||
|
||||
MAP.put(LOCAL_EXTENSION_PROPERTY, "Local extension properties are not allowed");
|
||||
MAP.put(LOCAL_VARIABLE_WITH_GETTER, "Local variables are not allowed to have getters");
|
||||
MAP.put(LOCAL_VARIABLE_WITH_SETTER, "Local variables are not allowed to have setters");
|
||||
|
||||
@@ -60,7 +60,7 @@ private val DEFAULT_CALL_CHECKERS = listOf(
|
||||
MissingDependencySupertypeChecker.ForCalls, AbstractClassInstantiationChecker, SuspendConversionCallChecker,
|
||||
UnitConversionCallChecker, FunInterfaceConstructorReferenceChecker, NullableExtensionOperatorWithSafeCallChecker,
|
||||
ReferencingToUnderscoreNamedParameterOfCatchBlockChecker, VarargWrongExecutionOrderChecker, SelfCallInNestedObjectConstructorChecker,
|
||||
NewSchemeOfIntegerOperatorResolutionChecker, EnumEntryVsCompanionPriorityCallChecker,
|
||||
NewSchemeOfIntegerOperatorResolutionChecker, EnumEntryVsCompanionPriorityCallChecker, CompanionInParenthesesLHSCallChecker,
|
||||
)
|
||||
private val DEFAULT_TYPE_CHECKERS = emptyList<AdditionalTypeChecker>()
|
||||
private val DEFAULT_CLASSIFIER_USAGE_CHECKERS = listOf(
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtParenthesizedExpression
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
|
||||
/**
|
||||
* Deprecate callable references in a form of (SomeClass)::name when SomeClass has a companion
|
||||
* and `(SomeClass)` is being used just like a value reference to the companion
|
||||
*/
|
||||
object CompanionInParenthesesLHSCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
val callableReference = resolvedCall.call.callElement.parent as? KtCallableReferenceExpression ?: return
|
||||
val parenthesizedExpression = callableReference.lhs as? KtParenthesizedExpression ?: return
|
||||
val unwrappedLhs = parenthesizedExpression.expression ?: return
|
||||
val expressionReceiver = resolvedCall.call.explicitReceiver as? ExpressionReceiver ?: return
|
||||
|
||||
val referencedClass = expressionReceiver.type.constructor.declarationDescriptor as? ClassDescriptor ?: return
|
||||
if (!referencedClass.isCompanionObject) return
|
||||
|
||||
// We should also consider cases like (package.MyClassWithCompanion)::foo
|
||||
val simpleReference =
|
||||
((unwrappedLhs as? KtDotQualifiedExpression)?.selectorExpression ?: unwrappedLhs) as? KtReferenceExpression
|
||||
?: return
|
||||
|
||||
if (context.trace.bindingContext[BindingContext.SHORT_REFERENCE_TO_COMPANION_OBJECT, simpleReference] == null) return
|
||||
|
||||
context.trace.report(Errors.PARENTHESIZED_COMPANION_LHS_DEPRECATION.on(parenthesizedExpression))
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ internal val propertiesPhase = makeIrFilePhase(
|
||||
description = "Move fields and accessors for properties to their classes, " +
|
||||
"replace calls to default property accessors with field accesses, " +
|
||||
"remove unused accessors and create synthetic methods for property annotations",
|
||||
stickyPostconditions = setOf((PropertiesLowering)::checkNoProperties)
|
||||
stickyPostconditions = setOf(PropertiesLowering.Companion::checkNoProperties)
|
||||
)
|
||||
|
||||
internal val IrClass.isGeneratedLambdaClass: Boolean
|
||||
|
||||
+2
-2
@@ -27,10 +27,10 @@ fun test() {
|
||||
val r4 = test.C.Companion::foo
|
||||
checkSubtype<() -> String>(r4)
|
||||
|
||||
val r5 = (C)::foo
|
||||
val r5 = <!PARENTHESIZED_COMPANION_LHS_DEPRECATION!>(C)<!>::foo
|
||||
checkSubtype<() -> String>(r5)
|
||||
|
||||
val r6 = (test.C)::foo
|
||||
val r6 = <!PARENTHESIZED_COMPANION_LHS_DEPRECATION!>(test.C)<!>::foo
|
||||
checkSubtype<() -> String>(r6)
|
||||
|
||||
val c = C.Companion
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// !CHECK_TYPE
|
||||
// SKIP_TXT
|
||||
|
||||
// FILE: lib.kt
|
||||
package test.abc
|
||||
|
||||
class V {
|
||||
companion object
|
||||
}
|
||||
|
||||
val V.a: String
|
||||
get() = "1"
|
||||
|
||||
val V.Companion.a: Int
|
||||
get() = 1
|
||||
|
||||
// FILE: main.kt
|
||||
import test.abc.V
|
||||
import test.abc.a
|
||||
import kotlin.reflect.KProperty0
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
fun case() {
|
||||
(V)::a checkType { <!INAPPLICABLE_CANDIDATE!>_<!><KProperty0<Int>>() }
|
||||
(V)::a checkType { _<KProperty1<V, String>>() }
|
||||
|
||||
(test.abc.V)::a checkType { <!INAPPLICABLE_CANDIDATE!>_<!><KProperty0<Int>>() }
|
||||
(test.abc.V)::a checkType { _<KProperty1<V, String>>() }
|
||||
|
||||
V::a checkType { _<KProperty1<V, String>>() }
|
||||
V.Companion::a checkType { _<KProperty0<Int>>() }
|
||||
|
||||
(V.Companion)::a checkType { _<KProperty0<Int>>() }
|
||||
}
|
||||
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
// !CHECK_TYPE
|
||||
// SKIP_TXT
|
||||
|
||||
// FILE: lib.kt
|
||||
package test.abc
|
||||
|
||||
class V {
|
||||
companion object
|
||||
}
|
||||
|
||||
val V.a: String
|
||||
get() = "1"
|
||||
|
||||
val V.Companion.a: Int
|
||||
get() = 1
|
||||
|
||||
// FILE: main.kt
|
||||
import test.abc.V
|
||||
import test.abc.a
|
||||
import kotlin.reflect.KProperty0
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
fun case() {
|
||||
<!PARENTHESIZED_COMPANION_LHS_DEPRECATION!>(V)<!>::a checkType { _<KProperty0<Int>>() }
|
||||
<!PARENTHESIZED_COMPANION_LHS_DEPRECATION!>(V)<!>::a checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><KProperty1<V, String>>() }
|
||||
|
||||
<!PARENTHESIZED_COMPANION_LHS_DEPRECATION!>(test.abc.V)<!>::a checkType { _<KProperty0<Int>>() }
|
||||
<!PARENTHESIZED_COMPANION_LHS_DEPRECATION!>(test.abc.V)<!>::a checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><KProperty1<V, String>>() }
|
||||
|
||||
V::a checkType { _<KProperty1<V, String>>() }
|
||||
V.Companion::a checkType { _<KProperty0<Int>>() }
|
||||
|
||||
(V.Companion)::a checkType { _<KProperty0<Int>>() }
|
||||
}
|
||||
+1
-1
@@ -21,5 +21,5 @@ val ok4 = E.Entry::hashCode
|
||||
fun hashCode() {}
|
||||
|
||||
val fail3 = <!UNSUPPORTED_FEATURE!>""<!>::hashCode
|
||||
val fail4 = <!UNSUPPORTED_FEATURE!>(C)<!>::hashCode
|
||||
val fail4 = <!PARENTHESIZED_COMPANION_LHS_DEPRECATION, UNSUPPORTED_FEATURE!>(C)<!>::hashCode
|
||||
val fail5 = <!UNSUPPORTED_FEATURE!>(C.Companion)<!>::hashCode
|
||||
|
||||
Generated
+6
@@ -2237,6 +2237,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/correctInfoAfterArrayLikeCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("deprecatedCompanionReceiverInParentheses.kt")
|
||||
public void testDeprecatedCompanionReceiverInParentheses() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/deprecatedCompanionReceiverInParentheses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ea81649_errorPropertyLHS.kt")
|
||||
public void testEa81649_errorPropertyLHS() throws Exception {
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import libCase1.*
|
||||
import kotlin.text.format
|
||||
|
||||
fun case1() {
|
||||
val y2 : () ->String =(String)::<!DEBUG_INFO_CALL("fqName: libCase1.format; typeCall: variable")!>format<!>
|
||||
val y2 : () ->String =<!PARENTHESIZED_COMPANION_LHS_DEPRECATION!>(String)<!>::<!DEBUG_INFO_CALL("fqName: libCase1.format; typeCall: variable")!>format<!>
|
||||
}
|
||||
|
||||
// FILE: LibCase1.kt
|
||||
@@ -78,7 +78,7 @@ import libCase3.format
|
||||
import kotlin.text.*
|
||||
|
||||
fun case3() {
|
||||
val y1 =(String)::<!DEBUG_INFO_CALL("fqName: libCase3.format; typeCall: variable")!>format<!>
|
||||
val y1 =<!PARENTHESIZED_COMPANION_LHS_DEPRECATION!>(String)<!>::<!DEBUG_INFO_CALL("fqName: libCase3.format; typeCall: variable")!>format<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.reflect.KProperty0<kotlin.Unit>")!>y1<!>
|
||||
|
||||
val y2 =""::<!DEBUG_INFO_CALL("fqName: libCase3.format; typeCall: variable")!>format<!>
|
||||
|
||||
+4
-4
@@ -22,12 +22,12 @@ package testsCase1
|
||||
|
||||
class Case() {
|
||||
fun case(v: V) {
|
||||
val va: () -> String = (V)::<!DEBUG_INFO_CALL("fqName: testsCase1.a; typeCall: variable")!>a<!>
|
||||
val va: () -> String = <!PARENTHESIZED_COMPANION_LHS_DEPRECATION!>(V)<!>::<!DEBUG_INFO_CALL("fqName: testsCase1.a; typeCall: variable")!>a<!>
|
||||
|
||||
val vb: () -> String = (V)::<!DEBUG_INFO_CALL("fqName: testsCase1.V.Companion.b; typeCall: variable")!>b<!>
|
||||
val vb: () -> String = <!PARENTHESIZED_COMPANION_LHS_DEPRECATION!>(V)<!>::<!DEBUG_INFO_CALL("fqName: testsCase1.V.Companion.b; typeCall: variable")!>b<!>
|
||||
|
||||
val va1: () -> String = v::<!DEBUG_INFO_CALL("fqName: testsCase1.a; typeCall: variable")!>a<!>
|
||||
val vb1: () -> String = (V)::<!DEBUG_INFO_CALL("fqName: testsCase1.V.Companion.b; typeCall: variable")!>b<!>
|
||||
val vb1: () -> String = <!PARENTHESIZED_COMPANION_LHS_DEPRECATION!>(V)<!>::<!DEBUG_INFO_CALL("fqName: testsCase1.V.Companion.b; typeCall: variable")!>b<!>
|
||||
|
||||
}
|
||||
|
||||
@@ -47,4 +47,4 @@ class V {
|
||||
companion object {
|
||||
const val b: String = "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class KotlinVersionsTest : KtUsefulTestCase() {
|
||||
|
||||
versions.add(
|
||||
ForTestCompileRuntime.runtimeJarClassLoader().loadClass(KotlinVersion::class.qualifiedName!!)
|
||||
.getDeclaredField((KotlinVersion)::CURRENT.name)
|
||||
.getDeclaredField(KotlinVersion.Companion::CURRENT.name)
|
||||
.get(null)
|
||||
.toString()
|
||||
.toVersion("KotlinVersion.CURRENT")
|
||||
|
||||
+5
@@ -2232,6 +2232,11 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("deprecatedCompanionReceiverInParentheses.kt")
|
||||
public void testDeprecatedCompanionReceiverInParentheses() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/deprecatedCompanionReceiverInParentheses.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ea81649_errorPropertyLHS.kt")
|
||||
public void testEa81649_errorPropertyLHS() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/ea81649_errorPropertyLHS.kt");
|
||||
|
||||
Reference in New Issue
Block a user