@@ -568,17 +568,19 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
568568 expected : CgVariable ? ,
569569 actual : CgVariable ,
570570 depth : Int ,
571- visitedModels : MutableSet <UtModel >,
571+ visitedModels : MutableSet <ModelWithField >,
572+ expectedModelField : FieldId ? = null,
572573 ) {
573- if (expectedModel in visitedModels) return
574+ val modelWithField = ModelWithField (expectedModel, expectedModelField)
575+ if (modelWithField in visitedModels) return
574576
575577 var expected = expected
576578 if (expected == null ) {
577579 require(! needExpectedDeclaration(expectedModel))
578580 expected = actual
579581 }
580582
581- visitedModels + = expectedModel
583+ visitedModels + = modelWithField
582584
583585 with (testFrameworkManager) {
584586 if (depth >= DEEP_EQUALS_MAX_DEPTH ) {
@@ -897,7 +899,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
897899 expected : CgVariable ,
898900 actual : CgVariable ,
899901 depth : Int ,
900- visitedModels : MutableSet <UtModel >
902+ visitedModels : MutableSet <ModelWithField >
901903 ) {
902904 // if field is static, it is represents itself in "before" and
903905 // "after" state: no need to assert its equality to itself.
@@ -906,7 +908,8 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
906908 }
907909
908910 // if model is already processed, so we don't want to add new statements
909- if (fieldModel in visitedModels) {
911+ val modelWithField = ModelWithField (fieldModel, fieldId)
912+ if (modelWithField in visitedModels) {
910913 currentBlock + = testFrameworkManager.getDeepEqualsAssertion(expected, actual).toStatement()
911914 return
912915 }
@@ -928,7 +931,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
928931 expected : CgVariable ,
929932 actual : CgVariable ,
930933 depth : Int ,
931- visitedModels : MutableSet <UtModel >
934+ visitedModels : MutableSet <ModelWithField >
932935 ) {
933936 // fieldModel is not visited and will be marked in assertDeepEquals call
934937 val fieldName = fieldId.name
@@ -950,6 +953,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
950953 actualFieldDeclaration.variable,
951954 depth + 1 ,
952955 visitedModels,
956+ fieldId,
953957 )
954958 emptyLineIfNeeded()
955959 }
@@ -960,7 +964,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
960964 expected : CgVariable ,
961965 actual : CgVariable ,
962966 depth : Int ,
963- visitedModels : MutableSet <UtModel >
967+ visitedModels : MutableSet <ModelWithField >
964968 ) {
965969 val fieldResultModels = fieldsOfExecutionResults[fieldId to depth]
966970 val nullResultModelInExecutions = fieldResultModels?.find { it.isNull() }
@@ -999,6 +1003,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
9991003 actualFieldDeclaration.variable,
10001004 depth + 1 ,
10011005 visitedModels,
1006+ fieldId,
10021007 )
10031008 }
10041009 )
@@ -1009,6 +1014,7 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
10091014 actualFieldDeclaration.variable,
10101015 depth + 1 ,
10111016 visitedModels,
1017+ fieldId,
10121018 )
10131019 }
10141020 emptyLineIfNeeded()
@@ -1270,6 +1276,14 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
12701276 .onFailure { exception -> processExecutionFailure(exception, executionResult) }
12711277 }
12721278
1279+ // Class is required to verify, if current model has already been analyzed in deepEquals.
1280+ // Using model without related field (if it is present) in comparison is incorrect,
1281+ // for example, for [UtNullModel] as they are equal to each other..
1282+ private data class ModelWithField (
1283+ val fieldModel : UtModel ,
1284+ val relatedField : FieldId ? ,
1285+ )
1286+
12731287 /* *
12741288 * We can't use standard deepEquals method in parametrized tests
12751289 * because nullable objects require different asserts.
0 commit comments