diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesPropagationData.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesPropagationData.java index b4b0ea5a516..d167592b365 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesPropagationData.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesPropagationData.java @@ -72,7 +72,9 @@ public class SignaturesPropagationData { createAutoMethodDescriptor(containingClass, method, autoReturnType, autoValueParameters, autoTypeParameters); superFunctions = getSuperFunctionsForMethod(method, autoMethodDescriptor, containingClass); - modifiedValueParameters = modifyValueParametersAccordingToSuperMethods(autoValueParameters); + modifiedValueParameters = superFunctions.isEmpty() + ? new ValueParameters(null, autoValueParameters, /* stableParameterNames = */false) + : modifyValueParametersAccordingToSuperMethods(autoValueParameters); } @NotNull @@ -198,9 +200,18 @@ public class SignaturesPropagationData { // TODO: Add propagation for other kotlin descriptors (KT-3621) Name name = method.getName(); - Method autoSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(autoMethodDescriptor); + Method autoSignature = null; + boolean autoMethodContainsVararg = SignaturePropagationUtilKt.containsVarargs(autoMethodDescriptor); for (KotlinType supertype : containingClass.getTypeConstructor().getSupertypes()) { - Collection superFunctionCandidates = supertype.getMemberScope().getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS); + Collection superFunctionCandidates = + supertype.getMemberScope().getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS); + + if (!autoMethodContainsVararg && !SignaturePropagationUtilKt.containsAnyNotTrivialSignature(superFunctionCandidates)) continue; + + if (autoSignature == null) { + autoSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(autoMethodDescriptor); + } + for (FunctionDescriptor candidate : superFunctionCandidates) { Method candidateSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(candidate); if (KotlinToJvmSignatureMapperKt.erasedSignaturesEqualIgnoringReturnTypes(autoSignature, candidateSignature)) { diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/signaturePropagationUtil.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/signaturePropagationUtil.kt new file mode 100644 index 00000000000..02fd23bbafd --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/signaturePropagationUtil.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.resolve.jvm.kotlinSignature + +import org.jetbrains.kotlin.descriptors.FunctionDescriptor + +internal fun FunctionDescriptor.containsVarargs() = valueParameters.any { it.varargElementType != null } + +internal fun Collection.containsAnyNotTrivialSignature() = any { it.hasNotTrivialSignature() } + +private fun FunctionDescriptor.hasNotTrivialSignature(): Boolean { + if (extensionReceiverParameter != null) return true + if (hasStableParameterNames()) return true + + return containsVarargs() +}