From 76b451db68b3b92b8d3d4ca2d247e34c829bc159 Mon Sep 17 00:00:00 2001 From: Arsen Nagdalian Date: Thu, 21 Jul 2022 17:51:45 +0300 Subject: [PATCH] Change type of 'actual' variable Before the type of this variable was the same as the return type of executable under test. However, this could lead to undesired reflection usage: if a method returns 'A', but the real type of 'actual' variable is 'B' (subclass of A), then we will not be able to access fields that are declared in 'B' without reflection, because the variable is declared with type 'A'. For example, this can happen when we make assertions on field modifications and some of these fields are from 'B', but are not accessible, because type 'A' knows nothing about these new fields. --- .../codegen/model/constructor/tree/CgMethodConstructor.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt index 165134a0c5..976b1275e8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt @@ -1076,7 +1076,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c emptyLineIfNeeded() actual = newVar( - CgClassId(executable.returnType, isNullable = result is UtNullModel), + CgClassId(result.classId, isNullable = result is UtNullModel), "actual" ) { thisInstance[executable](*methodArguments.toTypedArray())