javac 1.7 bug workaround: give error for language level 1.7 despite of java 1.8 would compile the code (IDEA-166358)

This commit is contained in:
Anna Kozlova
2017-01-12 12:02:35 +01:00
parent 19cd72788b
commit 65ac360725
3 changed files with 18 additions and 4 deletions
@@ -18,8 +18,6 @@ package com.intellij.psi;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.projectRoots.JavaVersionService;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.text.StringUtil;
@@ -211,8 +209,8 @@ public class PsiDiamondTypeImpl extends PsiDiamondType {
final DiamondInferenceResult result = new DiamondInferenceResult(classOrAnonymousClassReference.getReferenceName() + "<>");
if (PsiUtil.isRawSubstitutor(staticFactory, inferredSubstitutor)) {
if (!JavaVersionService.getInstance().isAtLeast(newExpression, JavaSdkVersion.JDK_1_8) &&
PsiUtil.skipParenthesizedExprUp(newExpression.getParent()) instanceof PsiExpressionList) {
//http://www.oracle.com/technetwork/java/javase/8-compatibility-guide-2156366.html#A999198 REF 7144506
if (!PsiUtil.isLanguageLevel8OrHigher(newExpression) && PsiUtil.skipParenthesizedExprUp(newExpression.getParent()) instanceof PsiExpressionList) {
for (PsiTypeParameter ignored : parameters) {
result.addInferredType(PsiType.getJavaLangObject(newExpression.getManager(), GlobalSearchScope.allScope(newExpression.getProject())));
}
@@ -0,0 +1,12 @@
import java.util.*;
class Test {
void foo() {
set<error descr="'set(java.util.List<java.lang.String>)' in 'Test' cannot be applied to '(java.util.ArrayList<java.lang.Object>)'">(new ArrayList<>(new Vector()))</error>;
}
void set(List<String> list) {
}
}
@@ -618,4 +618,8 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testUncheckedConversionInReturnType() throws Exception {
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
}
public void testNotErasedReturnValueUnderJdk7() throws Exception {
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_8, false);
}
}