mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
bad code green: reject return type constraint if unchecked conversion was applied during applicability check and return type is type parameter
This commit is contained in:
+6
@@ -689,6 +689,12 @@ public class InferenceSession {
|
||||
public void registerReturnTypeConstraints(PsiType returnType, PsiType targetType) {
|
||||
returnType = substituteWithInferenceVariables(returnType);
|
||||
if (myErased) {
|
||||
final InferenceVariable inferenceVariable = getInferenceVariable(returnType);
|
||||
if (inferenceVariable != null) {
|
||||
final PsiSubstitutor substitutor = resolveSubset(Collections.singletonList(inferenceVariable), mySiteSubstitutor);
|
||||
returnType = substitutor.substitute(inferenceVariable);
|
||||
if (returnType == null) return;
|
||||
}
|
||||
addConstraint(new TypeCompatibilityConstraint(targetType, TypeConversionUtil.erasure(returnType)));
|
||||
}
|
||||
else if (FunctionalInterfaceParameterizationUtil.isWildcardParameterized(returnType)) {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
class Foo<T extends Enum> {
|
||||
public T bar(Class<? extends T> type, String str) {
|
||||
<error descr="Incompatible types. Found: 'java.lang.Enum', required: 'T'">return Enum.valueOf(type, str);</error>
|
||||
return Enum.valueOf(<error descr="'valueOf(java.lang.Class<T>, java.lang.String)' in 'java.lang.Enum' cannot be applied to '(java.lang.Class<capture<? extends T>>, java.lang.String)'">type</error>, str);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ abstract class Group {
|
||||
}
|
||||
|
||||
public <T extends Category> T get(Key<T> key) {
|
||||
<error descr="Incompatible types. Found: 'Category', required: 'T'">return getCategory(key);</error>
|
||||
return getCategory<error descr="'getCategory(Key<R>)' in 'Group' cannot be applied to '(Key<T>)'">(key)</error>;
|
||||
}
|
||||
|
||||
public abstract <R extends Category<R>> R getCategory(Key<R> key);
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
<T> T foo(List<T> l) {
|
||||
return l.get(0);
|
||||
}
|
||||
|
||||
void m(List l){
|
||||
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'boolean'">boolean foo = foo(l);</error>
|
||||
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String'">String s = foo(l);</error>
|
||||
}
|
||||
}
|
||||
+4
@@ -429,6 +429,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPrimitiveTypeInReturnConstraintWithUncheckedConversion() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testVariableNamesOfNestedCalls() throws Exception {
|
||||
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
|
||||
String filePath = BASE_PATH + "/" + getTestName(false) + ".java";
|
||||
|
||||
Reference in New Issue
Block a user