JVM_IR: fix a bug when isInlineParameter is applied to default stubs
If an inline parameter has a default value, its type is nullable. There's already code to handle this in `IrInlineCodegen`, but it really should be in `isInlineParameter` instead, otherwise e.g. SyntheticAccessorLowering fails.
This commit is contained in:
+1
-2
@@ -82,8 +82,7 @@ class IrInlineCodegen(
|
||||
super.genValueAndPut(irValueParameter, argumentExpression, parameterType, codegen, blockInfo)
|
||||
}
|
||||
|
||||
// after transformation inlinable lambda parameter with default value would have nullable type: check default value type first
|
||||
val isInlineParameter = irValueParameter.isInlineParameter(irValueParameter.defaultValue?.expression?.type ?: irValueParameter.type)
|
||||
val isInlineParameter = irValueParameter.isInlineParameter()
|
||||
if (isInlineParameter && isInlineIrExpression(argumentExpression)) {
|
||||
val irReference: IrFunctionReference =
|
||||
(argumentExpression as IrBlock).statements.filterIsInstance<IrFunctionReference>().single()
|
||||
|
||||
+1
-3
@@ -20,9 +20,7 @@ fun extractDefaultLambdaOffsetAndDescriptor(
|
||||
|
||||
val valueParameterOffset = if (irFunction.extensionReceiverParameter != null) 1 else 0
|
||||
|
||||
return irFunction.valueParameters.filter {
|
||||
it.defaultValue != null && it.isInlineParameter(it.defaultValue!!.expression.type)
|
||||
}.associateBy {
|
||||
return irFunction.valueParameters.filter { it.defaultValue != null && it.isInlineParameter() }.associateBy {
|
||||
parameterOffsets[valueParameterOffset + it.index]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,8 +168,12 @@ fun IrFunction.hasPlatformDependent(): Boolean = propertyIfAccessor.hasAnnotatio
|
||||
fun IrFunction.getJvmVisibilityOfDefaultArgumentStub() =
|
||||
if (Visibilities.isPrivate(visibility) || isInlineOnly()) JavaVisibilities.PACKAGE_VISIBILITY else Visibilities.PUBLIC
|
||||
|
||||
fun IrValueParameter.isInlineParameter(type: IrType = this.type) =
|
||||
index >= 0 && !isNoinline && !type.isNullable() && (type.isFunction() || type.isSuspendFunctionTypeOrSubtype())
|
||||
fun IrValueParameter.isInlineParameter() =
|
||||
index >= 0 && !isNoinline && (type.isFunction() || type.isSuspendFunctionTypeOrSubtype()) &&
|
||||
// Parameters with default values are always nullable, so check the expression too.
|
||||
// Note that the frontend has a diagnostic for nullable inline parameters, so actually
|
||||
// making this return `false` requires using `@Suppress`.
|
||||
(!type.isNullable() || defaultValue?.expression?.type?.isNullable() == false)
|
||||
|
||||
val IrStatementOrigin?.isLambda: Boolean
|
||||
get() = this == IrStatementOrigin.LAMBDA || this == IrStatementOrigin.ANONYMOUS_FUNCTION
|
||||
|
||||
Reference in New Issue
Block a user