Skip to content

Commit e106126

Browse files
committed
Construct assemble models for classes with val-properties in constructor
1 parent 195999f commit e106126

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,6 @@ class AssembleModelGenerator(private val basePackageName: String) {
254254
if (fieldId.isStatic) {
255255
throw AssembleException("Static field $fieldId can't be set in an object of the class $classId")
256256
}
257-
if (fieldId.isFinal) {
258-
throw AssembleException("Final field $fieldId can't be set in an object of the class $classId")
259-
}
260257
if (!fieldId.type.isAccessibleFrom(basePackageName)) {
261258
throw AssembleException(
262259
"Field $fieldId can't be set in an object of the class $classId because its type is inaccessible"
@@ -266,6 +263,10 @@ class AssembleModelGenerator(private val basePackageName: String) {
266263
if (fieldId in constructorInfo.affectedFields ||
267264
(fieldId !in constructorInfo.setFields && !fieldModel.hasDefaultValue())
268265
) {
266+
// Kotlin can set final fields in constructor, so we should only check for final fields not affected by constructor
267+
if (fieldId.isFinal) {
268+
throw AssembleException("Final field $fieldId can't be set in an object of the class $classId")
269+
}
269270
val assembledModel = assembleModel(fieldModel)
270271
val modifierCall = modifierCall(this, fieldId, assembledModel)
271272
callChain.add(modifierCall)

0 commit comments

Comments
 (0)