inference: raise unchecked warning if low/equals bounds are not assignable without unchecked conversion (IDEA-150495)

This commit is contained in:
Anna Kozlova
2016-01-20 12:30:42 +01:00
parent 2fccc87268
commit 7e15b3fb59
4 changed files with 30 additions and 6 deletions

View File

@@ -1085,6 +1085,11 @@ public class InferenceSession {
return registerIncompatibleErrorMessage(var, incompatibleBoundsMessage);
} else {
type = eqBound;
if (!TypeConversionUtil.isAssignable(eqBound, lowerBound, false)) {
setErased();
}
}
}
else {
@@ -1110,10 +1115,10 @@ public class InferenceSession {
for (PsiType upperType : var.getBounds(InferenceBound.UPPER)) {
if (isProperType(upperType) ) {
String incompatibleBoundsMessage = null;
if (type != lowerBound && !TypeConversionUtil.isAssignable(substitutor.substitute(upperType), type)) {
if (type != lowerBound && !TypeConversionUtil.isAssignable(upperType, type)) {
incompatibleBoundsMessage = incompatibleBoundsMessage(var, substitutor, InferenceBound.EQ, EQUALITY_CONSTRAINTS_PRESENTATION, InferenceBound.UPPER, UPPER_BOUNDS_PRESENTATION);
}
else if (type == lowerBound && !TypeConversionUtil.isAssignable(substitutor.substitute(upperType), lowerBound)) {
else if (type == lowerBound && !TypeConversionUtil.isAssignable(upperType, lowerBound)) {
incompatibleBoundsMessage = incompatibleBoundsMessage(var, substitutor, InferenceBound.LOWER, LOWER_BOUNDS_PRESENTATION, InferenceBound.UPPER, UPPER_BOUNDS_PRESENTATION);
}
if (incompatibleBoundsMessage != null) {

View File

@@ -60,10 +60,6 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
if (((PsiClassType)exprType).resolve() == null) {
return true;
}
if (((PsiClassType)exprType).isRaw()) {
session.setErased();
}
}
if (exprType != null && exprType != PsiType.NULL) {

View File

@@ -0,0 +1,19 @@
import java.util.HashSet;
class Issue {
public void some(String group) {
new HashSet<Permission>().stream()
.map(permission -> (PrincipalPermission) permission)
.filter(permission -> group.equals(permission.getGroup()));
}
}
class Permission {
}
class PrincipalPermission<<warning descr="Type parameter 'T' is never used">T</warning>> extends Permission {
public String getGroup() {
return null;
}
}

View File

@@ -950,4 +950,8 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
public void testCastingCapturedWildcardToArray() throws Exception {
doTest();
}
public void testCheckUncheckedAssignmentDuringVariablesResaolution() throws Exception {
doTest(true);
}
}