mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
inference: ensure erasure flag is pushed to the container expression
IDEA-185316
This commit is contained in:
+1
-16
@@ -1926,22 +1926,7 @@ public class InferenceSession {
|
||||
|
||||
public static boolean wasUncheckedConversionPerformed(PsiElement call) {
|
||||
final Boolean erased = call.getUserData(ERASED);
|
||||
if (erased != null && erased.booleanValue()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (call instanceof PsiCallExpression) {
|
||||
PsiExpressionList args = ((PsiCallExpression)call).getArgumentList();
|
||||
if (args != null) {
|
||||
for (PsiExpression expression : args.getExpressions()) {
|
||||
if (expression instanceof PsiNewExpression && !PsiDiamondType.hasDiamond((PsiNewExpression)expression)) {
|
||||
continue;
|
||||
}
|
||||
if (wasUncheckedConversionPerformed(expression)) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return erased != null && erased.booleanValue();
|
||||
}
|
||||
|
||||
public PsiElement getContext() {
|
||||
|
||||
+4
@@ -180,6 +180,10 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
|
||||
callSession.registerReturnTypeConstraints(siteSubstitutor.substitute(returnType), targetType, expression);
|
||||
}
|
||||
if (callSession.repeatInferencePhases()) {
|
||||
if (callSession.isErased() &&
|
||||
!JavaGenericsUtil.isReifiableType(targetType) && session.getInferenceVariable(targetType) == null) {
|
||||
session.setErased();
|
||||
}
|
||||
return callSession;
|
||||
}
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
class A<T extends A> {
|
||||
|
||||
public A(){}
|
||||
public A(Collection<Integer> x, Consumer<? super T> y) {}
|
||||
|
||||
public void failToCompile(Consumer<? super T> x) {}
|
||||
|
||||
public A<T> add(A x) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void fail(Collection x) {
|
||||
A<A> builder = new A<>();
|
||||
builder.add(new A<>(x, A::notify))
|
||||
.failToCompile(A::notify);
|
||||
builder.failToCompile(A::notify);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class B<K> {
|
||||
abstract List<String> add(B b);
|
||||
abstract <Z> B<Z> create(List<String> l, Consumer<?> c);
|
||||
|
||||
void f(List l, B b) {
|
||||
String o = add(create(l, (t) -> t.hashCode())).get(0);//fails to compile in java 8, compiles in java 9, 10
|
||||
String o1 = add(create(l, (t) -> {})).get(0);
|
||||
String o2 = add(b).get(0);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInsight.daemon.lambda;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
|
||||
public class UncheckedWarningInferenceTest extends LightDaemonAnalyzerTestCase {
|
||||
private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/unchecked/";
|
||||
|
||||
public void testDontTreatAsUncheckedIfRawWasAssignedInRawParameter() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
|
||||
doTest(BASE_PATH + getTestName(false) + ".java", false, false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user