Fix AssertionError on overloading function with property in actual class
#KT-22352 Fixed
This commit is contained in:
@@ -153,6 +153,10 @@ object PositioningStrategies {
|
||||
TypeParameterUpperBounds, TypeParameterVariance, TypeParameterReified -> {
|
||||
(element as? KtTypeParameterListOwner)?.typeParameterList
|
||||
}
|
||||
CallableKind -> {
|
||||
(callableDeclaration as? KtNamedFunction)?.funKeyword
|
||||
?: (callableDeclaration as? KtProperty)?.valOrVarKeyword
|
||||
}
|
||||
ParameterShape -> {
|
||||
callableDeclaration?.let { it.receiverTypeReference ?: it.valueParameterList }
|
||||
}
|
||||
|
||||
+5
@@ -161,6 +161,8 @@ object ExpectedActualResolver {
|
||||
sealed class Incompatible(val reason: String?, val kind: IncompatibilityKind = IncompatibilityKind.WEAK) : Compatibility() {
|
||||
// Callables
|
||||
|
||||
object CallableKind : Incompatible("callable kinds are different (function vs property)", IncompatibilityKind.STRONG)
|
||||
|
||||
object ParameterShape : Incompatible("parameter shapes are different (extension vs non-extension)", IncompatibilityKind.STRONG)
|
||||
|
||||
object ParameterCount : Incompatible("number of value parameters is different", IncompatibilityKind.STRONG)
|
||||
@@ -227,6 +229,9 @@ object ExpectedActualResolver {
|
||||
"This function should be invoked only for declarations in the same kind of container (both members or both top level): $a, $b"
|
||||
}
|
||||
|
||||
if (a is FunctionDescriptor && b !is FunctionDescriptor ||
|
||||
a !is FunctionDescriptor && b is FunctionDescriptor) return Incompatible.CallableKind
|
||||
|
||||
val aExtensionReceiver = a.extensionReceiverParameter
|
||||
val bExtensionReceiver = b.extensionReceiverParameter
|
||||
if ((aExtensionReceiver != null) != (bExtensionReceiver != null)) return Incompatible.ParameterShape
|
||||
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
expect class Foo {
|
||||
val bar: String
|
||||
}
|
||||
|
||||
// MODULE: m1-jvm(m1-common)
|
||||
// FILE: jvm.kt
|
||||
|
||||
actual class Foo {
|
||||
actual val bar = "bar"
|
||||
fun bar() = bar
|
||||
}
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// -- Module: <m1-common> --
|
||||
package
|
||||
|
||||
public final expect class Foo {
|
||||
public expect final val bar: 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
|
||||
}
|
||||
|
||||
|
||||
// -- Module: <m1-jvm> --
|
||||
package
|
||||
|
||||
public final actual class Foo {
|
||||
public constructor Foo()
|
||||
public actual final val bar: kotlin.String = "bar"
|
||||
public final fun bar(): 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
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
expect class Foo {
|
||||
val bar: String
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
actual class Foo {
|
||||
actual fun bar(): String = ""
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
-- Common --
|
||||
Exit code: OK
|
||||
Output:
|
||||
|
||||
-- JVM --
|
||||
Exit code: COMPILATION_ERROR
|
||||
Output:
|
||||
compiler/testData/multiplatform/classScopes/functionAndPropertyWithSameName/jvm.kt:3:14: error: actual class 'Foo' has no corresponding members for expected class members:
|
||||
|
||||
public expect final val bar: String
|
||||
|
||||
The following declaration is incompatible because callable kinds are different (function vs property):
|
||||
public final actual fun bar(): String
|
||||
|
||||
actual class Foo {
|
||||
^
|
||||
compiler/testData/multiplatform/classScopes/functionAndPropertyWithSameName/jvm.kt:4:12: error: actual function 'bar' has no corresponding expected declaration
|
||||
The following declaration is incompatible because callable kinds are different (function vs property):
|
||||
public expect final val bar: String
|
||||
|
||||
actual fun bar(): String = ""
|
||||
^
|
||||
@@ -14470,6 +14470,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionAndPropertyWithSameName.kt")
|
||||
public void testFunctionAndPropertyWithSameName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/headerClass/functionAndPropertyWithSameName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("genericClassImplTypeAlias.kt")
|
||||
public void testGenericClassImplTypeAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/headerClass/genericClassImplTypeAlias.kt");
|
||||
|
||||
Generated
+6
@@ -14470,6 +14470,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionAndPropertyWithSameName.kt")
|
||||
public void testFunctionAndPropertyWithSameName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/headerClass/functionAndPropertyWithSameName.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("genericClassImplTypeAlias.kt")
|
||||
public void testGenericClassImplTypeAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/headerClass/genericClassImplTypeAlias.kt");
|
||||
|
||||
Generated
+6
@@ -153,6 +153,12 @@ public class MultiPlatformIntegrationTestGenerated extends AbstractMultiPlatform
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionAndPropertyWithSameName")
|
||||
public void testFunctionAndPropertyWithSameName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/multiplatform/classScopes/functionAndPropertyWithSameName/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionIncorrectSignature")
|
||||
public void testFunctionIncorrectSignature() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/multiplatform/classScopes/functionIncorrectSignature/");
|
||||
|
||||
Reference in New Issue
Block a user