Compatibility warning for references to companion via name (KT-13934)
This commit is contained in:
+10
@@ -1939,6 +1939,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionObjectMemberViaClassName.kt")
|
||||
public void testReferenceToCompanionObjectMemberViaClassName() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionObjectMemberViaClassNameCompatibility.kt")
|
||||
public void testReferenceToCompanionObjectMemberViaClassNameCompatibility() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("rewriteAtSliceOnGetOperator.kt")
|
||||
public void testRewriteAtSliceOnGetOperator() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.kt");
|
||||
|
||||
Generated
+5
@@ -2685,6 +2685,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionMember.kt")
|
||||
public void testReferenceToCompanionMember() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortListOfStrings.kt")
|
||||
public void testSortListOfStrings() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
|
||||
|
||||
+9
-2
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.DISPATCH_RE
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.EXTENSION_RECEIVER
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.DetailedReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
|
||||
@@ -213,7 +214,7 @@ class CallableReferencesCandidateFactory(
|
||||
callComponents.builtIns
|
||||
)
|
||||
|
||||
if (needCompatibilityWarning(callableReferenceAdaptation)) {
|
||||
if (needCompatibilityWarning(callableReferenceAdaptation, candidateDescriptor)) {
|
||||
diagnostics.add(LowerPriorityToPreserveCompatibility)
|
||||
}
|
||||
|
||||
@@ -261,7 +262,13 @@ class CallableReferencesCandidateFactory(
|
||||
)
|
||||
}
|
||||
|
||||
private fun needCompatibilityWarning(callableReferenceAdaptation: CallableReferenceAdaptation?): Boolean {
|
||||
private fun needCompatibilityWarning(
|
||||
callableReferenceAdaptation: CallableReferenceAdaptation?,
|
||||
candidate: CallableDescriptor
|
||||
): Boolean {
|
||||
// KT-13934: reference to companion object member via class name
|
||||
if (candidate.containingDeclaration.isCompanionObject() && argument.lhsResult is LHSResult.Type) return true
|
||||
|
||||
if (callableReferenceAdaptation == null) return false
|
||||
|
||||
return callableReferenceAdaptation.defaults != 0 ||
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
fun foo(): String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
companion object {
|
||||
fun foo(): String = "Fail"
|
||||
}
|
||||
}
|
||||
|
||||
fun B.foo(): String = "OK"
|
||||
|
||||
fun call(f: Any): String = if (f is Function0<*>) f.invoke() as String else (f as Function1<B, String>).invoke(B())
|
||||
|
||||
fun box(): String {
|
||||
val call1 = call(A::foo)
|
||||
if (call1 != "OK") return "fail 1: $call1"
|
||||
|
||||
// Checking compatibility mode: should be resolved to extensions in 1.4
|
||||
val call2 = call(B::foo)
|
||||
if (call2 != "OK") return "fail 2: $call2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
fun foo(): Int = 0
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
fun foo(): String = ""
|
||||
|
||||
companion object {
|
||||
fun foo(): Int = 0
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> call(f: () -> T): T = f()
|
||||
|
||||
fun testA(a: A) {
|
||||
val call1 = call(A::foo)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>call1<!>
|
||||
|
||||
val call2 = call(A.Companion::foo)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>call2<!>
|
||||
}
|
||||
|
||||
fun testB(b: B) {
|
||||
val call1 = call(B::foo)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>call1<!>
|
||||
|
||||
val call2 = call(B()::foo)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>call2<!>
|
||||
|
||||
val call3 = call(B.Companion::foo)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>call3<!>
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ T> call(/*0*/ f: () -> T): T
|
||||
public fun testA(/*0*/ a: A): kotlin.Unit
|
||||
public fun testB(/*0*/ b: B): kotlin.Unit
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
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
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
public final class B {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
fun foo(): Int = 0
|
||||
}
|
||||
}
|
||||
|
||||
fun A.foo(): Double = 0.0
|
||||
fun Any.foo(): Float = 1f
|
||||
|
||||
class B {
|
||||
fun foo(): String = ""
|
||||
|
||||
companion object {
|
||||
fun foo(): Int = 0
|
||||
}
|
||||
}
|
||||
|
||||
fun B.foo(): Double = 0.0
|
||||
|
||||
fun call(a: Any) {}
|
||||
|
||||
fun testA(a: A) {
|
||||
call(A::foo)
|
||||
call(A.Companion::foo)
|
||||
}
|
||||
|
||||
fun testB(b: B) {
|
||||
call(B::foo)
|
||||
call(B()::foo)
|
||||
call(B.Companion::foo)
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
fun foo(): Int = 0
|
||||
}
|
||||
}
|
||||
|
||||
fun A.foo(): Double = 0.0
|
||||
fun Any.foo(): Float = 1f
|
||||
|
||||
class B {
|
||||
fun foo(): String = ""
|
||||
|
||||
companion object {
|
||||
fun foo(): Int = 0
|
||||
}
|
||||
}
|
||||
|
||||
fun B.<!EXTENSION_SHADOWED_BY_MEMBER!>foo<!>(): Double = 0.0
|
||||
|
||||
fun call(a: Any) {}
|
||||
|
||||
fun testA(a: A) {
|
||||
call(<!COMPATIBILITY_WARNING!>A::foo<!>)
|
||||
call(A.Companion::foo)
|
||||
}
|
||||
|
||||
fun testB(b: B) {
|
||||
call(B::foo)
|
||||
call(B()::foo)
|
||||
call(B.Companion::foo)
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package
|
||||
|
||||
public fun call(/*0*/ a: kotlin.Any): kotlin.Unit
|
||||
public fun testA(/*0*/ a: A): kotlin.Unit
|
||||
public fun testB(/*0*/ b: B): kotlin.Unit
|
||||
public fun A.foo(): kotlin.Double
|
||||
public fun B.foo(): kotlin.Double
|
||||
public fun kotlin.Any.foo(): kotlin.Float
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
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
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
public final class B {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -1946,6 +1946,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionObjectMemberViaClassName.kt")
|
||||
public void testReferenceToCompanionObjectMemberViaClassName() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionObjectMemberViaClassNameCompatibility.kt")
|
||||
public void testReferenceToCompanionObjectMemberViaClassNameCompatibility() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("rewriteAtSliceOnGetOperator.kt")
|
||||
public void testRewriteAtSliceOnGetOperator() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.kt");
|
||||
|
||||
Generated
+10
@@ -1941,6 +1941,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionObjectMemberViaClassName.kt")
|
||||
public void testReferenceToCompanionObjectMemberViaClassName() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionObjectMemberViaClassNameCompatibility.kt")
|
||||
public void testReferenceToCompanionObjectMemberViaClassNameCompatibility() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("rewriteAtSliceOnGetOperator.kt")
|
||||
public void testRewriteAtSliceOnGetOperator() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.kt");
|
||||
|
||||
+5
@@ -2705,6 +2705,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionMember.kt")
|
||||
public void testReferenceToCompanionMember() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortListOfStrings.kt")
|
||||
public void testSortListOfStrings() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
|
||||
|
||||
+5
@@ -2705,6 +2705,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionMember.kt")
|
||||
public void testReferenceToCompanionMember() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortListOfStrings.kt")
|
||||
public void testSortListOfStrings() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
|
||||
|
||||
+5
@@ -2685,6 +2685,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionMember.kt")
|
||||
public void testReferenceToCompanionMember() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortListOfStrings.kt")
|
||||
public void testSortListOfStrings() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
|
||||
|
||||
Generated
+5
@@ -2065,6 +2065,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionMember.kt")
|
||||
public void testReferenceToCompanionMember() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortListOfStrings.kt")
|
||||
public void testSortListOfStrings() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
|
||||
|
||||
Generated
+5
@@ -2075,6 +2075,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionMember.kt")
|
||||
public void testReferenceToCompanionMember() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortListOfStrings.kt")
|
||||
public void testSortListOfStrings() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
|
||||
|
||||
+5
@@ -2075,6 +2075,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToCompanionMember.kt")
|
||||
public void testReferenceToCompanionMember() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortListOfStrings.kt")
|
||||
public void testSortListOfStrings() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
|
||||
|
||||
Reference in New Issue
Block a user