Load 'equals' parameter from Java code with the name 'other'
This fixes a lot of warnings on mixed Kotlin+Java code about different names for the same parameter because we always loaded 'equals' parameter with the name 'p0', whereas in Kotlin we usually name it 'other'
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ package test
|
||||
public final class ClassWithObjectMethod : java.lang.Object {
|
||||
public constructor ClassWithObjectMethod()
|
||||
protected/*protected and package*/ open override /*1*/ /*fake_override*/ fun clone(): jet.Any
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ p0: jet.Any?): jet.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: jet.Any?): jet.Boolean
|
||||
protected/*protected and package*/ open override /*1*/ /*fake_override*/ fun finalize(): jet.Unit
|
||||
public final override /*1*/ /*fake_override*/ fun getClass(): java.lang.Class<out jet.Any?>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): jet.Int
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package test
|
||||
|
||||
public trait InterfaceWithObjectMethods : java.lang.Object {
|
||||
public abstract override /*1*/ fun clone(): jet.Any?
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ p0: jet.Any?): jet.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: jet.Any?): jet.Boolean
|
||||
public abstract override /*1*/ fun finalize(): jet.Unit
|
||||
public final override /*1*/ /*fake_override*/ fun getClass(): java.lang.Class<out jet.Any?>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): jet.Int
|
||||
|
||||
+15
-2
@@ -188,12 +188,25 @@ public abstract class LazyJavaMemberScope(
|
||||
else Pair(jetType, null)
|
||||
}
|
||||
|
||||
val name = if (function.getName().asString() == "equals" &&
|
||||
jValueParameters.size() == 1 &&
|
||||
KotlinBuiltIns.getInstance().getNullableAnyType() == outType) {
|
||||
// This is a hack to prevent numerous warnings on Kotlin classes that inherit Java classes: if you override "equals" in such
|
||||
// class without this hack, you'll be warned that in the superclass the name is "p0" (regardless of the fact that it's
|
||||
// "other" in Any)
|
||||
// TODO: fix Java parameter name loading logic somehow (don't always load "p0", "p1", etc.)
|
||||
Name.identifier("other")
|
||||
}
|
||||
else {
|
||||
// TODO: parameter names may be drawn from attached sources, which is slow; it's better to make them lazy
|
||||
javaParameter.getName() ?: Name.identifier("p$index")
|
||||
}
|
||||
|
||||
ValueParameterDescriptorImpl(
|
||||
function,
|
||||
index,
|
||||
c.resolveAnnotations(javaParameter),
|
||||
// TODO: parameter names may be drawn from attached sources, which is slow; it's better to make them lazy
|
||||
javaParameter.getName() ?: Name.identifier("p$index"),
|
||||
name,
|
||||
outType,
|
||||
false,
|
||||
varargElementType
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// "class org.jetbrains.jet.plugin.quickfix.AddFunctionParametersFix" "false"
|
||||
// ERROR: Too many arguments for public open fun equals(p0: jet.Any?): jet.Boolean defined in java.lang.Object
|
||||
// ERROR: Too many arguments for public open fun equals(other: jet.Any?): jet.Boolean defined in java.lang.Object
|
||||
|
||||
fun f(d: java.lang.Object) {
|
||||
d.equals("a", <caret>"b")
|
||||
|
||||
Reference in New Issue
Block a user