Don't skip coercion to nullable Unit in codegen
This commit is contained in:
+10
-10
@@ -160,7 +160,7 @@ class ExpressionCodegen(
|
|||||||
//coerceNotToUnit(r.type, Type.VOID_TYPE)
|
//coerceNotToUnit(r.type, Type.VOID_TYPE)
|
||||||
exp.accept(this, data)
|
exp.accept(this, data)
|
||||||
}
|
}
|
||||||
return coerceNotToUnit(result.type, expression.asmType)
|
return coerceNotToUnit(result.type, expression.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitMemberAccess(expression: IrMemberAccessExpression, data: BlockInfo): StackValue {
|
override fun visitMemberAccess(expression: IrMemberAccessExpression, data: BlockInfo): StackValue {
|
||||||
@@ -279,8 +279,7 @@ class ExpressionCodegen(
|
|||||||
mv.aconst(null)
|
mv.aconst(null)
|
||||||
mv.athrow()
|
mv.athrow()
|
||||||
} else if (expression.descriptor !is ConstructorDescriptor) {
|
} else if (expression.descriptor !is ConstructorDescriptor) {
|
||||||
val expectedTypeOnStack = returnType?.let { typeMapper.mapType(it) } ?: callable.returnType
|
return returnType?.run { coerceNotToUnit(callable.returnType, this) } ?: onStack(callable.returnType)
|
||||||
return coerceNotToUnit(callable.returnType, expectedTypeOnStack)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return expression.onStack
|
return expression.onStack
|
||||||
@@ -534,10 +533,10 @@ class ExpressionCodegen(
|
|||||||
|
|
||||||
|
|
||||||
override fun visitWhen(expression: IrWhen, data: BlockInfo): StackValue =
|
override fun visitWhen(expression: IrWhen, data: BlockInfo): StackValue =
|
||||||
genIfWithBranches(expression.branches[0], data, expression.asmType, expression.branches.drop(1))
|
genIfWithBranches(expression.branches[0], data, expression.type, expression.branches.drop(1))
|
||||||
|
|
||||||
|
|
||||||
private fun genIfWithBranches(branch: IrBranch, data: BlockInfo, type: Type, otherBranches: List<IrBranch>): StackValue {
|
private fun genIfWithBranches(branch: IrBranch, data: BlockInfo, type: KotlinType, otherBranches: List<IrBranch>): StackValue {
|
||||||
val elseLabel = Label()
|
val elseLabel = Label()
|
||||||
val condition = branch.condition
|
val condition = branch.condition
|
||||||
val thenBranch = branch.result
|
val thenBranch = branch.result
|
||||||
@@ -933,10 +932,11 @@ class ExpressionCodegen(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun coerceNotToUnit(fromType: Type, toType: Type): StackValue {
|
private fun coerceNotToUnit(fromType: Type, toType: KotlinType): StackValue {
|
||||||
if (toType != AsmTypes.UNIT_TYPE) {
|
val asmType = toType.asmType
|
||||||
coerce(fromType, toType, mv)
|
if (asmType != AsmTypes.UNIT_TYPE || TypeUtils.isNullableType(toType)) {
|
||||||
return onStack(toType)
|
coerce(fromType, asmType, mv)
|
||||||
|
return onStack(asmType)
|
||||||
}
|
}
|
||||||
return onStack(fromType)
|
return onStack(fromType)
|
||||||
}
|
}
|
||||||
@@ -1091,4 +1091,4 @@ fun DefaultCallArgs.generateOnStackIfNeeded(callGenerator: IrCallGenerator, isCo
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
return toInts.isNotEmpty()
|
return toInts.isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user