diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/IrInterpreter.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/IrInterpreter.kt index 6a1b9bf038f..84afbc3468b 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/IrInterpreter.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/IrInterpreter.kt @@ -252,7 +252,7 @@ class IrInterpreter(irModule: IrModuleFragment, private val bodyMap: Map().toPrimitiveStateArray(expression.getVarargType(i)!!)) // if vararg is empty - if (stack.peekReturnValue().isNull() && !valueParametersSymbols[i].isNullable()) { + stack.peekReturnValue().checkNullability(valueParametersSymbols[i].owner.type) { val method = irFunction.getCapitalizedFileName() + "." + irFunction.fqNameWhenAvailable val parameter = valueParametersSymbols[i].owner.name throw IllegalArgumentException("Parameter specified as non-null is null: method $method, parameter $parameter") diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/Utils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/Utils.kt index 210de640b89..73d67a0383e 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/Utils.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/Utils.kt @@ -204,17 +204,4 @@ internal fun State?.getCorrectReceiverByFunction(irFunction: IrFunction): State? return generateSequence(original) { it.superClass }.firstOrNull { it.irClass.thisReceiver == other } ?: this } -internal fun State.checkNullability(irType: IrType?): State { - if (irType !is IrSimpleType) return this - if (this.isNull() && !irType.hasQuestionMark) { - throw NullPointerException() - } - return this -} - -fun IrValueParameterSymbol.isNullable(): Boolean { - val type = this.owner.type as? IrSimpleType ?: return false - return type.isNullable() -} - internal fun IrFunction.getCapitalizedFileName() = this.file.name.replace(".kt", "Kt").capitalize() \ No newline at end of file diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/state/State.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/state/State.kt index a60b5c8d251..0f65a5fb25b 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/state/State.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/state/State.kt @@ -55,4 +55,15 @@ internal fun State.isSubtypeOf(other: IrType): Boolean { } return this.irClass.defaultType.isSubtypeOfClass(other.classOrNull!!) +} + +/** + * This method used to check if for not null parameter there was passed null argument. + */ +internal fun State.checkNullability(irType: IrType?, throwException: () -> Nothing = { throw NullPointerException() }): State { + if (irType !is IrSimpleType) return this + if (this.isNull() && !irType.isNullable()) { + throwException() + } + return this } \ No newline at end of file