Skip to content

Commit 9fd7984

Browse files
authored
Fix creation of variables for class fields #2638 (#2713)
1 parent deedfc7 commit 9fd7984

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

utbot-spring-framework/src/main/kotlin/org/utbot/framework/codegen/tree/fieldmanager/CgAbstractClassFieldManager.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,21 @@ abstract class CgAbstractClassFieldManager(context: CgContext) :
4545

4646
val baseVarName = constructBaseVarName(model)
4747

48-
// `withNameScope` is used to avoid saving names for sub-models of model
48+
/*
49+
* `withNameScope` is used to avoid saving names for sub-models of model.
50+
*
51+
* Different models from different executions may have the same id.
52+
* Therefore, when creating a variable for a new class field and using existing `currentTestSetId` and `currentExecutionId`,
53+
* field`s `model.wrap()` may match one of the values in `annotatedModels`.
54+
* To avoid false matches when creating a variable for a new class field, `withTestSetIdScope(-1)` and `withExecutionIdScope(-1)` are used.
55+
*/
4956
val createdVariable = withNameScope {
50-
variableConstructor.getOrCreateVariable(model, baseVarName) as? CgVariable
51-
?: error("`CgVariable` cannot be constructed from a $model model")
57+
withTestSetIdScope(-1) {
58+
withExecutionIdScope(-1) {
59+
variableConstructor.getOrCreateVariable(model, baseVarName) as? CgVariable
60+
?: error("`CgVariable` cannot be constructed from a $model model")
61+
}
62+
}
5263
}
5364
existingVariableNames.add(createdVariable.name)
5465

0 commit comments

Comments
 (0)