Fixed handling of default params in declaration (KT-23239)

This commit is contained in:
Roman Artemev
2018-03-16 20:45:08 +03:00
parent a121a4a6b2
commit 0d0adbbc05
3 changed files with 44 additions and 16 deletions
@@ -28,7 +28,8 @@ import org.jetbrains.kotlin.js.translate.utils.BindingUtils.getClassDescriptor
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.pureFqn
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils.getSupertypesWithoutFakes
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.descriptorUtil.hasOrInheritsParametersWithDefaultValue
import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue
import org.jetbrains.kotlin.resolve.calls.components.isActualParameterWithCorrespondingExpectedDefault
import org.jetbrains.kotlin.resolve.descriptorUtil.hasOwnParametersWithDefaultValue
class DeclarationBodyVisitor(
@@ -110,8 +111,12 @@ class DeclarationBodyVisitor(
initializerStatements.add(statement)
}
private fun hasParametersWithDefaultValue(descriptor: FunctionDescriptor) = descriptor.valueParameters.any { it.hasDefaultValue() }
private fun hasCorrespondingExpectParametersWithDefaultValue(descriptor: FunctionDescriptor) =
descriptor.valueParameters.any { it.isActualParameterWithCorrespondingExpectedDefault }
override fun addFunction(descriptor: FunctionDescriptor, expression: JsExpression?, psi: KtElement?) {
if (!descriptor.hasOrInheritsParametersWithDefaultValue() || !descriptor.isOverridableOrOverrides) {
if (!hasParametersWithDefaultValue(descriptor) || !descriptor.isOverridableOrOverrides) {
if (expression != null) {
context.addDeclarationStatement(context.addFunctionToPrototype(containingClass, descriptor, expression))
}
@@ -125,7 +130,7 @@ class DeclarationBodyVisitor(
context.addDeclarationStatement(JsAstUtils.assignment(functionRef, expression).makeStmt())
}
if (descriptor.hasOwnParametersWithDefaultValue()) {
if (descriptor.hasOwnParametersWithDefaultValue() || hasCorrespondingExpectParametersWithDefaultValue(descriptor)) {
val caller = JsFunction(context.getScopeForDescriptor(containingClass), JsBlock(), "")
caller.source = psi?.finalElement
val callerContext = context