Skip to content

Commit 15d2b4f

Browse files
authored
Construct assemble models for classes with val-properties in constructor #1190 (#1240)
1 parent 145da7d commit 15d2b4f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/assemble/AssembleModelGenerator.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,25 +254,27 @@ class AssembleModelGenerator(private val basePackageName: String) {
254254
instantiatedModels[compositeModel] = this
255255

256256
compositeModel.fields.forEach { (fieldId, fieldModel) ->
257+
//if field value has been filled by constructor or it is default, we suppose that it is already properly initialized
258+
if ((fieldId in constructorInfo.setFields || fieldModel.hasDefaultValue()) && fieldId !in constructorInfo.affectedFields)
259+
return@forEach
260+
257261
if (fieldId.isStatic) {
258262
throw AssembleException("Static field $fieldId can't be set in an object of the class $classId")
259263
}
260-
if (fieldId.isFinal) {
261-
throw AssembleException("Final field $fieldId can't be set in an object of the class $classId")
262-
}
264+
263265
if (!fieldId.type.isAccessibleFrom(basePackageName)) {
264266
throw AssembleException(
265267
"Field $fieldId can't be set in an object of the class $classId because its type is inaccessible"
266268
)
267269
}
268-
//fill field value if it hasn't been filled by constructor, and it is not default
269-
if (fieldId in constructorInfo.affectedFields ||
270-
(fieldId !in constructorInfo.setFields && !fieldModel.hasDefaultValue())
271-
) {
272-
val assembledModel = assembleModel(fieldModel)
273-
val modifierCall = modifierCall(this, fieldId, assembledModel)
274-
callChain.add(modifierCall)
270+
271+
if (fieldId.isFinal) {
272+
throw AssembleException("Final field $fieldId can't be set in an object of the class $classId")
275273
}
274+
275+
val assembledModel = assembleModel(fieldModel)
276+
val modifierCall = modifierCall(this, fieldId, assembledModel)
277+
callChain.add(modifierCall)
276278
}
277279

278280
callChain.toList()

0 commit comments

Comments
 (0)