Skip to content

Fix TypeUtils.isAssignable() for wildcards with multiple upper bounds - #1782

Open
Alwaysgaurav1 wants to merge 1 commit into
apache:masterfrom
Alwaysgaurav1:fix/typeutils-wildcard-multiple-bounds
Open

Fix TypeUtils.isAssignable() for wildcards with multiple upper bounds#1782
Alwaysgaurav1 wants to merge 1 commit into
apache:masterfrom
Alwaysgaurav1:fix/typeutils-wildcard-multiple-bounds

Conversation

@Alwaysgaurav1

Copy link
Copy Markdown
Contributor

Description

Fixes an issue in TypeUtils.isAssignable(Type, WildcardType, Map) where checking assignability of a WildcardType with multiple upper bounds (intersection types such as ? extends Serializable & Cloneable) to another WildcardType (such as ? extends Serializable) incorrectly returned false.

Root Cause

When the subject type is a WildcardType, the upper bounds loop previously enforced that every upper bound in the subject wildcard had to be assignable to each target upper bound toBound (forall bound in upperBounds: isAssignable(bound, toBound)):

for (Type toBound : toUpperBounds) {
    toBound = substituteTypeVariables(toBound, typeVarAssigns);
    for (final Type bound : upperBounds) {
        if (!isAssignable(bound, toBound, typeVarAssigns)) {
            return false;
        }
    }
}

@Alwaysgaurav1

Copy link
Copy Markdown
Contributor Author

@garydgregory, please review it quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant