erasure type of new expression if diamonds were used and during applicability check unchecked conversion was applied (IDEA-154009)

This commit is contained in:
Anna.Kozlova
2016-04-01 16:53:23 +02:00
parent 874d1a07d3
commit c1c40665ce
4 changed files with 54 additions and 0 deletions
@@ -58,6 +58,19 @@ public abstract class PsiDiamondType extends PsiType {
}
};
public static final DiamondInferenceResult RAW_RESULT = new DiamondInferenceResult() {
@NotNull
@Override
public PsiType[] getTypes() {
return PsiType.EMPTY_ARRAY;
}
@Override
public String getErrorMessage() {
return null;
}
};
public static final DiamondInferenceResult UNRESOLVED_CONSTRUCTOR = new DiamondInferenceResult() {
@NotNull
@Override
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.infos.MethodCandidateInfo;
import com.intellij.psi.scope.PsiConflictResolver;
@@ -178,6 +179,12 @@ public class PsiDiamondTypeImpl extends PsiDiamondType {
return DiamondInferenceResult.UNRESOLVED_CONSTRUCTOR;
}
//15.9.3 Choosing the Constructor and its Arguments
//The return type and throws clause of cj are the same as the return type and throws clause determined for mj (§15.12.2.6)
if (InferenceSession.wasUncheckedConversionPerformed(context)) {
return DiamondInferenceResult.RAW_RESULT;
}
final PsiMethod staticFactory = ((MethodCandidateInfo)staticFactoryInfo).getElement();
final PsiTypeParameter[] parameters = staticFactory.getTypeParameters();
final PsiElement staticFactoryContext = staticFactory.getContext();
@@ -0,0 +1,30 @@
class Test {
{
Holder h = null;
Result<String> r1 = new Result<><error descr="'Result(D)' in 'Result' cannot be applied to '(Holder)'">(h)</error>;
Result<String> r2 = Result.create<error descr="'create(K)' in 'Result' cannot be applied to '(Holder)'">(h)</error>;
Holder dataHolder = null;
Result<String> r3 = new Result<>(new Holder<>(dataHolder));
Result<String> r4 = Result.create(new Holder<>(dataHolder));
Result<String> r5 = new Result<>(Holder.create(dataHolder));
Result<String> r6 = Result.create(Holder.create(dataHolder));
}
}
class Result<D> {
Result(D data) {}
static <K> Result<K> create(K k) {
return null;
}
}
class Holder<E> {
Holder(Holder<E> holder) {}
static <M> Holder<M> create(Holder<M> m) {
return null;
}
}
@@ -63,6 +63,10 @@ public class Diamond8HighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testEraseTypeForNewExpressionWithDiamondsIfUncheckedConversionWasPerformedDuringApplicabilityCheck() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
}