Skip to content

Remove redundant and harmful casts in overloads processing #1642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down