mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
type arguments agree when one is type parameter and another is not any wildcard (IDEA-67427)
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
import java.lang.Double;
|
||||
|
||||
interface IConverter<C> {
|
||||
}
|
||||
|
||||
abstract class AbstractNumberConverter<N extends Number> implements IConverter<N> {
|
||||
}
|
||||
|
||||
class DoubleConverter extends AbstractNumberConverter<Double> {
|
||||
}
|
||||
|
||||
public class Test {
|
||||
public static <C> IConverter<C> getConverter(Class<C> type) {
|
||||
return (IConverter<C>)new DoubleConverter() {
|
||||
};
|
||||
}
|
||||
|
||||
public static <C extends String> IConverter<C> getConverter1(Class<C> type) {
|
||||
return <error descr="Inconvertible types; cannot cast 'DoubleConverter' to 'IConverter<C>'">(IConverter<C>)new DoubleConverter() {
|
||||
}</error>;
|
||||
}
|
||||
|
||||
public static <C extends Double> IConverter<C> getConverter2(Class<C> type) {
|
||||
return (IConverter<C>)new DoubleConverter() {
|
||||
};
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
IConverter<String> converter = getConverter(String.class);
|
||||
IConverter<String> converter1 = getConverter1(String.class);
|
||||
IConverter<String> converter2 = <error descr="Inferred type 'java.lang.String' for type parameter 'C' is not within its bound; should extend 'java.lang.Double'">getConverter2(String.class)</error>;
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testMethodSignatureEquality() throws Exception { doTest(false); }
|
||||
public void testInnerClassRef() throws Exception { doTest(false); }
|
||||
public void testPrivateInnerClassRef() throws Exception { doTest(false); }
|
||||
public void testWideningCastToTypeParam() throws Exception { doTest(false); }
|
||||
|
||||
public void testJavaUtilCollections_NoVerify() throws Exception {
|
||||
PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vcs.changes.IgnoredFileBean;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -862,6 +863,14 @@ public class TypeConversionUtil {
|
||||
}
|
||||
}
|
||||
else {
|
||||
final PsiClass leftClass = PsiUtil.resolveClassInType(typeLeft);
|
||||
if (leftClass instanceof PsiTypeParameter) {
|
||||
for (PsiClassType leftClassType : leftClass.getExtendsListTypes()) {
|
||||
if (TypesDistinctProver.provablyDistinct(leftClassType, typeRight)) return false;
|
||||
}
|
||||
if (!(typeRight instanceof PsiCapturedWildcardType || typeRight instanceof PsiWildcardType)) return true;
|
||||
}
|
||||
|
||||
return typeLeft.equals(typeRight);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user