Check for the presence of dispatch receiver too in isEqualsDescriptor()

Otherwise, top-level function with the name 'equals' and suitable
signature will be (erroneously) treated as true 'equals' invocation,
leading to further exception (see EA-126602)
This commit is contained in:
Dmitry Savvinov
2018-10-12 18:11:14 +03:00
parent 28e43b0487
commit 99e1d4ab45
5 changed files with 30 additions and 1 deletions
@@ -87,7 +87,7 @@ fun DeclarationDescriptor.isCallsInPlaceEffectDescriptor(): Boolean = equalsDslD
fun DeclarationDescriptor.isInvocationKindEnum(): Boolean = equalsDslDescriptor(INVOCATION_KIND_ENUM)
fun DeclarationDescriptor.isEqualsDescriptor(): Boolean =
this is FunctionDescriptor && this.name == Name.identifier("equals") && // fast checks
this is FunctionDescriptor && this.name == Name.identifier("equals") && dispatchReceiverParameter != null && // fast checks
this.returnType?.isBoolean() == true && this.valueParameters.singleOrNull()?.type?.isNullableAny() == true // signature matches
internal fun ResolvedCall<*>.firstArgumentAsExpressionOrNull(): KtExpression? =
@@ -0,0 +1,9 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_REFERENCE
class Foo
fun test(a: Foo, b: Foo) {
// Note that signature matches the 'equals'
fun equals(x: Any?): Boolean = false
equals(b)
}
@@ -0,0 +1,10 @@
package
public fun test(/*0*/ a: Foo, /*1*/ b: Foo): kotlin.Unit
public final class Foo {
public constructor Foo()
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
}
@@ -14501,6 +14501,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/override/ExtendFunctionClass.kt");
}
@TestMetadata("fakeEquals.kt")
public void testFakeEquals() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/fakeEquals.kt");
}
@TestMetadata("FakeOverrideAbstractAndNonAbstractFun.kt")
public void testFakeOverrideAbstractAndNonAbstractFun() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/FakeOverrideAbstractAndNonAbstractFun.kt");
@@ -14501,6 +14501,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/override/ExtendFunctionClass.kt");
}
@TestMetadata("fakeEquals.kt")
public void testFakeEquals() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/fakeEquals.kt");
}
@TestMetadata("FakeOverrideAbstractAndNonAbstractFun.kt")
public void testFakeOverrideAbstractAndNonAbstractFun() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/FakeOverrideAbstractAndNonAbstractFun.kt");