IDEA-63698 (Inconvertible type (assign double to Integer) not highlighted as error)

This commit is contained in:
Bas Leijdekkers
2013-09-14 22:13:13 +02:00
parent 0200babeca
commit e16694eabf
3 changed files with 19 additions and 5 deletions
@@ -361,7 +361,6 @@ public class HighlightUtil extends HighlightUtilBase {
@Nullable
static HighlightInfo checkAssignmentCompatibleTypes(@NotNull PsiAssignmentExpression assignment) {
if (!"=".equals(assignment.getOperationSign().getText())) return null;
PsiExpression lExpr = assignment.getLExpression();
PsiExpression rExpr = assignment.getRExpression();
if (rExpr == null) return null;
@@ -369,16 +368,27 @@ public class HighlightUtil extends HighlightUtilBase {
PsiType rType = rExpr.getType();
if (rType == null) return null;
HighlightInfo highlightInfo = checkAssignability(lType, rType, rExpr, assignment);
final IElementType sign = assignment.getOperationTokenType();
HighlightInfo highlightInfo;
if (JavaTokenType.EQ.equals(sign)) {
highlightInfo = checkAssignability(lType, rType, rExpr, assignment);
}
else {
// 15.26.2. Compound Assignment Operators
final IElementType opSign = TypeConversionUtil.convertEQtoOperation(sign);
final PsiType type = TypeConversionUtil.calcTypeForBinaryExpression(lType, rType, opSign, true);
if (type == null || lType == null || TypeConversionUtil.areTypesConvertible(type, lType)) {
return null;
}
highlightInfo = createIncompatibleTypeHighlightInfo(lType, type, assignment.getTextRange(), 0);
}
if (highlightInfo == null) {
return null;
}
registerChangeVariableTypeFixes(lExpr, rType, highlightInfo);
if (lType != null) {
registerChangeVariableTypeFixes(rExpr, lType, highlightInfo);
}
return highlightInfo;
}
@@ -42,5 +42,9 @@ public class a {
int i1='d';
<error descr="Incompatible types. Found: 'long', required: 'int'">int i2 = 1L;</error>
Integer destination = 25;
<error descr="Incompatible types. Found: 'double', required: 'java.lang.Integer'">destination += 2.0</error>;
Byte b = 1;
<error descr="Incompatible types. Found: 'int', required: 'java.lang.Byte'">b -= 1</error>;
}
}
@@ -119,7 +119,7 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testAssignToFinal() { doTest(false, false); }
public void testUnhandledExceptionsInSuperclass() { doTest(false, false); }
public void testNoUnhandledExceptionsMultipleInheritance() { doTest(false, false); }
public void testAssignmentCompatible () { doTest(false, false); }
public void testAssignmentCompatible () { setLanguageLevel(LanguageLevel.JDK_1_5); doTest(false, false); }
public void testMustBeBoolean() { doTest(false, false); }
public void testNumericLiterals() { doTest(false, false); }