Skip to content

Commit

Permalink
DeclarationSiteTypeVariance doesn't change bounds when they refer to …
Browse files Browse the repository at this point in the history
…final classes / issue #2621
  • Loading branch information
jkschneider committed Jan 11, 2023
1 parent 4ea75c7 commit c414e02
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,32 @@ void test(Function<String, Integer> f) {
)
);
}

@Test
void finalClasses() {
rewriteRun(
java(
"""
final class In {}
interface Out {}
"""
),
java(
"""
import java.util.function.Function;
class Test {
void test(Function<In, Out> f) {
}
}
""",
"""
import java.util.function.Function;
class Test {
void test(Function<In, ? extends Out> f) {
}
}
"""
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,15 @@ private J.ParameterizedType useDeclarationSiteVariance(J.ParameterizedType pt, V
variance == VariantTypeSpec.Variance.INVARIANT) {
return tp;
}
for (String excludedBound : excludedBounds) {
JavaType.FullyQualified fq = TypeUtils.asFullyQualified(tp.getType());
if (fq != null && StringUtils.matchesGlob(fq.getFullyQualifiedName(), excludedBound)) {

JavaType.FullyQualified fq = TypeUtils.asFullyQualified(tp.getType());
if (fq != null) {
for (String excludedBound : excludedBounds) {
if (StringUtils.matchesGlob(fq.getFullyQualifiedName(), excludedBound)) {
return tp;
}
}
if (fq.getFlags().contains(Flag.Final)) {
return tp;
}
}
Expand Down

0 comments on commit c414e02

Please sign in to comment.