Skip to content

Commit dd5176f

Browse files
committed
Fix invalid UTestCyclicReferenceDescriptor
1 parent a751085 commit dd5176f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/JcToUtExecutionConverter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class JcToUtExecutionConverter(
118118
} ?: return null
119119

120120
return utUsvmExecution
121+
.mapModels(jcToUtModelConverter.utCyclicReferenceModelResolver)
121122
.mapModels(constructAssemblingMapper())
122123
.mapModels(constructAssembleToCompositeModelMapper())
123124
.mapModels(constructConstArrayModelMapper())

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/JcToUtModelConverter.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ import org.usvm.instrumentation.testcase.descriptor.UTestObjectDescriptor
1313
import org.usvm.instrumentation.testcase.descriptor.UTestRefDescriptor
1414
import org.usvm.instrumentation.testcase.descriptor.UTestValueDescriptor
1515
import org.usvm.instrumentation.util.InstrumentationModuleConstants.nameForExistingButNullString
16+
import org.utbot.framework.plugin.api.ClassId
1617
import org.utbot.framework.plugin.api.FieldId
1718
import org.utbot.framework.plugin.api.UtArrayModel
1819
import org.utbot.framework.plugin.api.UtAssembleModel
1920
import org.utbot.framework.plugin.api.UtClassRefModel
2021
import org.utbot.framework.plugin.api.UtCompositeModel
22+
import org.utbot.framework.plugin.api.UtCustomModel
2123
import org.utbot.framework.plugin.api.UtEnumConstantModel
2224
import org.utbot.framework.plugin.api.UtModel
2325
import org.utbot.framework.plugin.api.UtNullModel
2426
import org.utbot.framework.plugin.api.UtPrimitiveModel
2527
import org.utbot.framework.plugin.api.UtReferenceModel
28+
import org.utbot.framework.plugin.api.mapper.UtModelDeepMapper
29+
import org.utbot.framework.plugin.api.mapper.UtModelMapper
2630
import org.utbot.framework.plugin.api.util.classClassId
2731
import org.utbot.framework.plugin.api.util.id
2832
import org.utbot.framework.plugin.api.util.jClass
@@ -33,6 +37,15 @@ enum class EnvironmentStateKind {
3337
INITIAL, FINAL
3438
}
3539

40+
data class UtCyclicReferenceModel(
41+
override val id: Int?,
42+
override val classId: ClassId,
43+
val refId: Int,
44+
val stateKind: EnvironmentStateKind,
45+
) : UtCustomModel(id, classId) {
46+
override fun shallowMap(mapper: UtModelMapper): UtCustomModel = this
47+
}
48+
3649
class JcToUtModelConverter(
3750
private val idGenerator: IdGenerator<Int>,
3851
private val jcClasspath: JcClasspath,
@@ -42,6 +55,13 @@ class JcToUtModelConverter(
4255
mutableMapOf<Pair<UTestValueDescriptor, EnvironmentStateKind>, UtModel>()
4356
private val refIdAndStateKindToDescriptorCache =
4457
mutableMapOf<Pair<Int, EnvironmentStateKind>, UTestValueDescriptor>()
58+
val utCyclicReferenceModelResolver = UtModelDeepMapper { model ->
59+
when (model) {
60+
is UtCyclicReferenceModel -> getModelByRefIdAndStateKind(model.refId, model.stateKind)
61+
?: error("Invalid UTestCyclicReferenceDescriptor: $model")
62+
else -> model
63+
}
64+
}
4565

4666
fun convert(
4767
valueDescriptor: UTestValueDescriptor,
@@ -149,7 +169,12 @@ class JcToUtModelConverter(
149169
is UTestConstantDescriptor.String -> constructString(valueDescriptor.value)
150170

151171
is UTestCyclicReferenceDescriptor -> getModelByRefIdAndStateKind(valueDescriptor.refId, stateKind)
152-
?: error("Invalid UTestCyclicReferenceDescriptor: $valueDescriptor")
172+
?: UtCyclicReferenceModel(
173+
id = curModelId,
174+
classId = valueDescriptor.type.classId,
175+
refId = valueDescriptor.refId,
176+
stateKind = stateKind
177+
)
153178

154179
is UTestEnumValueDescriptor -> UtEnumConstantModel(
155180
id = curModelId,

0 commit comments

Comments
 (0)