Skip to content

Handle not-nullable parameters in Kotlin constructors correctly #1336 #1352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class AssembleModelGenerator(private val basePackageName: String) {
val modelName = nextModelName(compositeModel.classId.jClass.simpleName.decapitalize())

val constructorId = findBestConstructorOrNull(compositeModel)
?: throw AssembleException("No default constructor to instantiate an object of the class ${compositeModel.id}")
?: throw AssembleException("No default constructor to instantiate an object of the class ${compositeModel.classId}")

val constructorInfo = constructorAnalyzer.analyze(constructorId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.utbot.framework.plugin.api.id
import org.utbot.framework.plugin.api.util.isArray
import org.utbot.framework.plugin.api.util.isRefType
import org.utbot.framework.plugin.api.util.jClass
import org.utbot.framework.util.kotlinIntrinsicsClassId
import soot.Scene
import soot.SootMethod
import soot.Type
Expand Down Expand Up @@ -173,8 +174,8 @@ class ConstructorAnalyzer {
val jimpleLocal = assn.rightOp as? JimpleLocal ?: continue

val field = (assn.leftOp as? JInstanceFieldRef)?.field ?: continue
val parameterIndex = jimpleBody.locals.indexOfFirst { it.name == jimpleLocal.name }
indexedFields[parameterIndex - 1] = FieldId(field.declaringClass.id, field.name)
val parameterIndex = jimpleBody.parameterLocals.indexOfFirst { it.name == jimpleLocal.name }
indexedFields[parameterIndex] = FieldId(field.declaringClass.id, field.name)
}

return indexedFields
Expand Down Expand Up @@ -226,6 +227,8 @@ class ConstructorAnalyzer {
jimpleBody.units
.filterIsInstance<JInvokeStmt>()
.map { it.invokeExpr }
// These are instructions inserted by Kotlin compiler to check that arguments are not null, we should ignore them
.filterNot { it.method.declaringClass.id == kotlinIntrinsicsClassId }

private fun sameParameterTypes(sootMethod: SootMethod, constructorId: ConstructorId): Boolean {
val sootConstructorTypes = sootMethod.parameterTypes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.utbot.framework.util

import org.utbot.framework.plugin.api.BuiltinClassId

val kotlinIntrinsicsClassId: BuiltinClassId
get() = BuiltinClassId(
simpleName = "Intrinsics",
canonicalName = "kotlin.jvm.internal.Intrinsics",
packageName = "kotlin.jvm.internal"
)