Skip to content

Commit

Permalink
SONARJAVA-1606 uses subtypeOf for typeVar to not lose method resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohops committed Mar 18, 2016
1 parent 2d30673 commit 90411d9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public boolean isSubtype(JavaType t, JavaType s) {
break;
case JavaType.CLASS:
case JavaType.WILDCARD:
case JavaType.TYPEVAR:
result = t.isSubtypeOf(s);
break;
case JavaType.BOT:
Expand Down
21 changes: 20 additions & 1 deletion java-frontend/src/test/files/sym/Generics.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,23 @@ interface MyInterface<T> {
}

class C<T> {
}
}

class TypeParameterUsedInMethods<T, U> {
Function<? super T, ? extends U> getter;

void foo(T val, U wantedValue) {
getter.apply(val);
// these 2 calls do not compile but methods are resolved, as argument matching is based on erasure
getter.apply(new Object());
getter.apply(wantedValue);
// not valid call with different erasure, not resolved
getter.apply("hello");
}

static class Function<X, Y> {
Y apply(X from) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public void Generics() {
//Inner class referenced as type parameter in super class/interface
assertThat(result.reference(68,53)).isSameAs(result.symbol("B", 69));

JavaSymbol applyMethod = result.symbol("apply");
assertThat(result.reference(83, 12)).isSameAs(applyMethod);
// FIXME SONARJAVA-1606 should be 1, subtyping of type variable is wrong
assertThat(applyMethod.usages()).hasSize(3);
}

@Test
Expand Down

0 comments on commit 90411d9

Please sign in to comment.