Extract logic to get function parameters for default value generation
For some reason, this logic was a bit different in JVM (FunctionCodegen) and JS (FunctionBodyTranslator). For example, in JS the EXPECTED_FUNCTION_SOURCE_WITH_DEFAULT_ARGUMENTS_NOT_FOUND diagnostic was reported even in the case when no expected function was found for the actual function at all, which made it quite difficult to write multiplatform sources for JS stdlib where it both should be compiled as a part of the multiplatform project, and by itself (suppressing NO_ACTUAL_FOR_EXPECT): in the latter case, the new error must have been suppressed everywhere as well #KT-21913
This commit is contained in:
+2
-19
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.js.translate.utils;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.backend.common.CodegenUtil;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -25,7 +24,6 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.js.backend.ast.*;
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.MetadataProperties;
|
||||
import org.jetbrains.kotlin.js.naming.NameSuggestion;
|
||||
@@ -38,7 +36,6 @@ import org.jetbrains.kotlin.js.translate.reference.ReferenceTranslator;
|
||||
import org.jetbrains.kotlin.psi.KtBlockExpression;
|
||||
import org.jetbrains.kotlin.psi.KtDeclarationWithBody;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
@@ -83,22 +80,8 @@ public final class FunctionBodyTranslator extends AbstractTranslator {
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
List<ValueParameterDescriptor> valueParameters = descriptor.getValueParameters();
|
||||
List<ValueParameterDescriptor> valueParametersForDefaultValue;
|
||||
if (descriptor.isActual() && CollectionsKt.none(valueParameters, ValueParameterDescriptor::declaresDefaultValue)) {
|
||||
FunctionDescriptor expected = CodegenUtil.findExpectedFunctionForActual(descriptor);
|
||||
if (expected != null) {
|
||||
valueParametersForDefaultValue = expected.getValueParameters();
|
||||
}
|
||||
else {
|
||||
PsiElement element = DescriptorToSourceUtils.descriptorToDeclaration(descriptor);
|
||||
assert element != null : "No element found for descriptor: " + descriptor;
|
||||
context.bindingTrace().report(Errors.EXPECTED_FUNCTION_SOURCE_WITH_DEFAULT_ARGUMENTS_NOT_FOUND.on(element));
|
||||
valueParametersForDefaultValue = valueParameters;
|
||||
}
|
||||
}
|
||||
else {
|
||||
valueParametersForDefaultValue = valueParameters;
|
||||
}
|
||||
List<ValueParameterDescriptor> valueParametersForDefaultValue =
|
||||
CodegenUtil.getFunctionParametersForDefaultValueGeneration(descriptor, context.bindingTrace());
|
||||
|
||||
List<JsStatement> result = new ArrayList<>(valueParameters.size());
|
||||
for (int i = 0; i < valueParameters.size(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user