EA-36903 - ISE: JavaTypeTransformer$.visitClassType
Using error types as type arguments when there's an error in a type instantiation in Java code
This commit is contained in:
+25
-17
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
@@ -39,6 +40,8 @@ import static org.jetbrains.jet.lang.resolve.java.TypeUsage.*;
|
||||
|
||||
public class JavaTypeTransformer {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(JavaTypeTransformer.class);
|
||||
|
||||
private JavaSemanticServices javaSemanticServices;
|
||||
private JavaDescriptorResolver resolver;
|
||||
@Inject
|
||||
@@ -175,25 +178,30 @@ public class JavaTypeTransformer {
|
||||
PsiType[] psiArguments = classType.getParameters();
|
||||
|
||||
if (parameters.size() != psiArguments.length) {
|
||||
throw new IllegalStateException(
|
||||
"parameters = " + parameters.size() + ", actual arguments = " + psiArguments.length
|
||||
+ " in " + classType.getPresentableText() + "\n PsiClass: \n" + psiClass.getText());
|
||||
}
|
||||
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
PsiType psiArgument = psiArguments[i];
|
||||
TypeParameterDescriptor typeParameterDescriptor = parameters.get(i);
|
||||
// Most of the time this means there is an error in the Java code
|
||||
LOG.warn("parameters = " + parameters.size() + ", actual arguments = " + psiArguments.length +
|
||||
" in " + classType.getPresentableText() + "\n PsiClass: \n" + psiClass.getText());
|
||||
|
||||
TypeUsage howTheProjectionIsUsed = howThisTypeIsUsed == SUPERTYPE ? SUPERTYPE_ARGUMENT : TYPE_ARGUMENT;
|
||||
TypeProjection typeProjection = transformToTypeProjection(
|
||||
psiArgument, typeParameterDescriptor, typeVariableResolver, howTheProjectionIsUsed);
|
||||
|
||||
if (typeProjection.getProjectionKind() == typeParameterDescriptor.getVariance()) {
|
||||
// remove redundant 'out' and 'in'
|
||||
arguments.add(new TypeProjection(Variance.INVARIANT, typeProjection.getType()));
|
||||
for (TypeParameterDescriptor parameter : parameters) {
|
||||
arguments.add(new TypeProjection(ErrorUtils.createErrorType(parameter.getName().getName())));
|
||||
}
|
||||
else {
|
||||
arguments.add(typeProjection);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
PsiType psiArgument = psiArguments[i];
|
||||
TypeParameterDescriptor typeParameterDescriptor = parameters.get(i);
|
||||
|
||||
TypeUsage howTheProjectionIsUsed = howThisTypeIsUsed == SUPERTYPE ? SUPERTYPE_ARGUMENT : TYPE_ARGUMENT;
|
||||
TypeProjection typeProjection = transformToTypeProjection(
|
||||
psiArgument, typeParameterDescriptor, typeVariableResolver, howTheProjectionIsUsed);
|
||||
|
||||
if (typeProjection.getProjectionKind() == typeParameterDescriptor.getVariance()) {
|
||||
// remove redundant 'out' and 'in'
|
||||
arguments.add(new TypeProjection(Variance.INVARIANT, typeProjection.getType()));
|
||||
}
|
||||
else {
|
||||
arguments.add(typeProjection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package test
|
||||
|
||||
public trait WrongNumberOfGenericParameters : java.lang.Object {
|
||||
public abstract fun o0() : test.WrongNumberOfGenericParameters.One<out jet.Any?>?
|
||||
public abstract fun o2() : test.WrongNumberOfGenericParameters.One<[ERROR : T]>?
|
||||
public abstract fun t1() : test.WrongNumberOfGenericParameters.Two<out jet.Any?, out jet.Any?>?
|
||||
public abstract fun z() : test.WrongNumberOfGenericParameters.Zero?
|
||||
|
||||
public trait One</*0*/ T> : java.lang.Object {
|
||||
}
|
||||
|
||||
public trait Two</*0*/ P, /*1*/ Q> : java.lang.Object {
|
||||
}
|
||||
|
||||
public trait Zero : java.lang.Object {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package test;
|
||||
|
||||
public interface WrongNumberOfGenericParameters {
|
||||
|
||||
interface Zero {}
|
||||
interface One<T> {}
|
||||
|
||||
Zero<String> z();
|
||||
|
||||
One o0();
|
||||
One<String, String> o2();
|
||||
|
||||
// This does not produce the expected result, because IDEA thinks Two<X> is a raw type
|
||||
interface Two<P, Q> {}
|
||||
Two<String> t1();
|
||||
}
|
||||
@@ -187,6 +187,11 @@ public final class LoadJavaCustomTest extends KotlinTestWithEnvironment {
|
||||
doTestNoCompile(dir + "ReturnNotSubtype.txt", dir);
|
||||
}
|
||||
|
||||
public void testWrongNumberOfGenericParameters() throws Exception {
|
||||
String dir = PATH + "/errors/";
|
||||
doTestNoCompile(dir + "WrongNumberOfGenericParameters.txt", dir);
|
||||
}
|
||||
|
||||
public static class SubclassingKotlinInJavaTest extends KotlinTestWithEnvironmentManagement {
|
||||
public void testSubclassingKotlinInJava() throws Exception {
|
||||
doTest(PATH + "/" + getTestName(true));
|
||||
|
||||
Reference in New Issue
Block a user