From 9f4c458517a13ebd3f15f55660d7c9f85a21a09b Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Mon, 9 Jan 2023 15:37:04 +0300 Subject: [PATCH] Remove redundant and harmful casts in overloads processing --- .../services/access/CgCallableAccessManager.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/access/CgCallableAccessManager.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/access/CgCallableAccessManager.kt index 898cb0037b..87ebbcd655 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/access/CgCallableAccessManager.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/access/CgCallableAccessManager.kt @@ -518,12 +518,15 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA // in case arg type exactly equals target type, do nothing if (arg.type == targetType) return@map arg - // arg type is subtype of target type - // check other overloads for ambiguous types - val typesInOverloadings = ambiguousOverloads.map { it.parameters[i] } - val ancestors = typesInOverloadings.filter { arg.type.isSubtypeOf(it) } - - if (ancestors.isNotEmpty()) typeCast(targetType, arg) else arg + // if we are here, arg type is a subtype of target type + // we should check other overloads for ambiguous types + val anotherTypesInOverloadings = ambiguousOverloads + .map { it.parameters[i] } + .filter { arg.type.isSubtypeOf(it) } + .filterNot { it == targetType } + .isNotEmpty() + + if (anotherTypesInOverloadings) typeCast(targetType, arg) else arg } /**