Skip to content

Commit 734d22a

Browse files
Fix: ValueConstructor and MockValueConstructor
1 parent f9f30f6 commit 734d22a

File tree

4 files changed

+6
-13
lines changed

4 files changed

+6
-13
lines changed

utbot-framework/src/main/kotlin/org/utbot/engine/ValueConstructor.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,12 @@ class ValueConstructor {
6262

6363
// TODO: JIRA:1379 -- replace UtReferenceModel with Int
6464
private val constructedObjects = HashMap<UtReferenceModel, Any?>()
65-
private val resultsCache = HashMap<UtReferenceModel, Any>()
6665
private val mockInfo = mutableListOf<MockInfo>()
6766
private var mockTarget: MockTarget? = null
6867
private var mockCounter = 0
6968

7069
private fun clearState() {
7170
constructedObjects.clear()
72-
resultsCache.clear()
7371
mockInfo.clear()
7472
mockTarget = null
7573
mockCounter = 0
@@ -337,7 +335,7 @@ class ValueConstructor {
337335
}
338336
}
339337

340-
return resultsCache[assembleModel]
338+
return constructedObjects[assembleModel]
341339
?: error("Can't assemble model: $assembleModel")
342340
}
343341

@@ -375,7 +373,7 @@ class ValueConstructor {
375373
assembleModel: UtAssembleModel,
376374
) {
377375
val executable = callModel.executable
378-
val instanceValue = resultsCache[callModel.instance]
376+
val instanceValue = callModel.instance?.let { value(it) }
379377
val params = callModel.params.map { value(it) }
380378

381379
val result = when (executable) {
@@ -386,7 +384,6 @@ class ValueConstructor {
386384
// Ignore result if returnId is null. Otherwise add it to instance cache.
387385
callModel.returnValue?.let {
388386
checkNotNull(result) { "Tracked instance can't be null for call $executable in model $assembleModel" }
389-
resultsCache[it] = result
390387

391388
//If statement is final instantiating, add result to constructed objects cache
392389
if (callModel == assembleModel.finalInstantiationModel) {
@@ -400,7 +397,7 @@ class ValueConstructor {
400397
*/
401398
private fun updateWithDirectSetFieldModel(directSetterModel: UtDirectSetFieldModel) {
402399
val instanceModel = directSetterModel.instance
403-
val instance = resultsCache[instanceModel] ?: error("Model $instanceModel is not instantiated")
400+
val instance = constructedObjects[instanceModel] ?: error("Model $instanceModel is not instantiated")
404401

405402
val instanceClassId = instanceModel.classId
406403
val fieldModel = directSetterModel.fieldModel

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.utbot.framework.assemble
22

33
import org.utbot.common.isPrivate
44
import org.utbot.common.isPublic
5-
import org.utbot.common.packageName
65
import org.utbot.engine.ResolvedExecution
76
import org.utbot.engine.ResolvedModels
87
import org.utbot.framework.UtSettings

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/MockValueConstructor.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class MockValueConstructor(
7979

8080
// TODO: JIRA:1379 -- replace UtReferenceModel with Int
8181
private val constructedObjects = HashMap<UtReferenceModel, Any>()
82-
private val resultsCache = HashMap<UtReferenceModel, Any>()
8382
private val mockInfo = mutableListOf<MockInfo>()
8483
private var mockTarget: MockTarget? = null
8584
private var mockCounter = 0
@@ -366,7 +365,7 @@ class MockValueConstructor(
366365
}
367366
}
368367

369-
return resultsCache[assembleModel] ?: error("Can't assemble model: $assembleModel")
368+
return constructedObjects[assembleModel] ?: error("Can't assemble model: $assembleModel")
370369
}
371370

372371
private fun constructFromLambdaModel(lambdaModel: UtLambdaModel): Any {
@@ -406,7 +405,7 @@ class MockValueConstructor(
406405
assembleModel: UtAssembleModel,
407406
) {
408407
val executable = callModel.executable
409-
val instanceValue = resultsCache[callModel.instance]
408+
val instanceValue = callModel.instance?.let { value(it) }
410409
val params = callModel.params.map { value(it) }
411410

412411
val result = when (executable) {
@@ -417,7 +416,6 @@ class MockValueConstructor(
417416
// Ignore result if returnId is null. Otherwise add it to instance cache.
418417
callModel.returnValue?.let {
419418
checkNotNull(result) { "Tracked instance can't be null for call $executable in model $assembleModel" }
420-
resultsCache[it] = result
421419

422420
//If statement is final instantiating, add result to constructed objects cache
423421
if (callModel == assembleModel.finalInstantiationModel) {
@@ -431,7 +429,7 @@ class MockValueConstructor(
431429
*/
432430
private fun updateWithDirectSetFieldModel(directSetterModel: UtDirectSetFieldModel) {
433431
val instanceModel = directSetterModel.instance
434-
val instance = resultsCache[instanceModel] ?: error("Model $instanceModel is not instantiated")
432+
val instance = value(instanceModel)
435433

436434
val instanceClassId = instanceModel.classId
437435
val fieldModel = directSetterModel.fieldModel

utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/providers/DateConstantModelProvider.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ class DateConstantModelProvider(
142142
"$dateFormatParse#" + id.hex(),
143143
instantiationChain
144144
).apply {
145-
instantiationChain += simpleDateFormatModel.allStatementsChain
146145
instantiationChain += UtExecutableCallModel(
147146
simpleDateFormatModel, dateFormatParse, listOf(UtPrimitiveModel(dateString)), returnValue = this
148147
)

0 commit comments

Comments
 (0)