JVM IR: erase parameter default value when copying it to bridge

#KT-48391 Fixed
This commit is contained in:
Alexander Udalov
2021-09-02 23:39:44 +02:00
parent bcafece28e
commit a06fc20680
12 changed files with 73 additions and 14 deletions
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.lazy.*
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
import org.jetbrains.kotlin.ir.linkage.IrProvider
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbol
@@ -241,13 +240,7 @@ abstract class DeclarationStubGenerator(
varargElementType?.toIrType(), isCrossinline, isNoinline, isHidden = false, isAssignable = false
).also { irValueParameter ->
if (descriptor.declaresDefaultValue()) {
irValueParameter.defaultValue =
irValueParameter.factory.createExpressionBody(
IrErrorExpressionImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, descriptor.type.toIrType(),
"Stub expression for default value of ${descriptor.name}"
)
)
irValueParameter.defaultValue = irValueParameter.createStubDefaultValue()
}
}
}
@@ -6,10 +6,7 @@
package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.*
@@ -174,6 +171,11 @@ fun IrExpression.coerceToUnitIfNeeded(valueType: IrType, irBuiltIns: IrBuiltIns,
fun IrFunctionAccessExpression.usesDefaultArguments(): Boolean =
symbol.owner.valueParameters.any { this.getValueArgument(it.index) == null }
fun IrValueParameter.createStubDefaultValue(): IrExpressionBody =
factory.createExpressionBody(
IrErrorExpressionImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, "Stub expression for default value of $name")
)
val IrClass.functions: Sequence<IrSimpleFunction>
get() = declarations.asSequence().filterIsInstance<IrSimpleFunction>()