Removing redundant projections when loading from Java.
This commit is contained in:
+14
-2
@@ -30,7 +30,10 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureReader;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.java.JavaTypeTransformer.TypeUsage.*;
|
||||
|
||||
@@ -186,7 +189,16 @@ public class JavaTypeTransformer {
|
||||
TypeParameterDescriptor typeParameterDescriptor = parameters.get(i);
|
||||
|
||||
TypeUsage howTheProjectionIsUsed = howThisTypeIsUsed == SUPERTYPE ? SUPERTYPE_ARGUMENT : TYPE_ARGUMENT;
|
||||
arguments.add(transformToTypeProjection(psiArgument, typeParameterDescriptor, typeVariableResolver, howTheProjectionIsUsed));
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -125,7 +125,6 @@ public class TypeParameterDescriptorImpl extends DeclarationDescriptorNonRootImp
|
||||
|
||||
@Override
|
||||
public Variance getVariance() {
|
||||
checkInitialized();
|
||||
return variance;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface RemoveRedundantProjectionKind {
|
||||
void f(Collection<? extends CharSequence> collection);
|
||||
void f(Comparable<? super CharSequence> comparator);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
public trait RemoveRedundantProjectionKind: Object {
|
||||
public fun f(p0: Collection<CharSequence?>?)
|
||||
public fun f(p0: Comparable<CharSequence?>?)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace test
|
||||
|
||||
public abstract trait test.RemoveRedundantProjectionKind : java.lang.Object {
|
||||
public abstract fun f(/*0*/ p0: jet.Collection<jet.CharSequence?>?): jet.Tuple0
|
||||
public abstract fun f(/*0*/ p0: jet.Comparable<jet.CharSequence?>?): jet.Tuple0
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError;
|
||||
|
||||
public class WrongTypeParameterBoundStructure1 {
|
||||
@ExpectLoadError("'java.lang.Runnable?' type in method signature has 0 type arguments, while 'Runnable<Int>' in alternative signature has 1 of them")
|
||||
@KotlinSignature("fun <A, B : Runnable<Int>> foo(a : A, b : List<out B>) where B : List<Cloneable>")
|
||||
@KotlinSignature("fun <A, B : Runnable<Int>> foo(a : A, b : List<B>) where B : List<Cloneable>")
|
||||
public <A, B extends Runnable & List<Cloneable>> void foo(A a, List<? extends B> b) {
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,6 +3,6 @@ package test
|
||||
import java.util.*
|
||||
|
||||
public open class WrongTypeParameterBoundStructure1 : Object() {
|
||||
public open fun <erased A, erased B : Runnable?> foo(p0 : A?, p1 : List<out B>?) where B : List<Cloneable?>? {
|
||||
public open fun <erased A, erased B : Runnable?> foo(p0 : A?, p1 : List<B>?) where B : List<Cloneable?>? {
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,5 +2,5 @@ namespace test
|
||||
|
||||
public open class test.WrongTypeParameterBoundStructure1 : java.lang.Object {
|
||||
public final /*constructor*/ fun <init>(): test.WrongTypeParameterBoundStructure1
|
||||
public open fun </*0*/ A : jet.Any?, /*1*/ B : java.lang.Runnable? & jet.List<java.lang.Cloneable?>?>foo(/*0*/ p0: A?, /*1*/ p1: jet.List<out B>?): jet.Tuple0
|
||||
public open fun </*0*/ A : jet.Any?, /*1*/ B : java.lang.Runnable? & jet.List<java.lang.Cloneable?>?>foo(/*0*/ p0: A?, /*1*/ p1: jet.List<B>?): jet.Tuple0
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError;
|
||||
|
||||
public class WrongTypeParameterBoundStructure2 {
|
||||
@ExpectLoadError("'jet.List<java.lang.Cloneable?>?' type in method signature has 1 type arguments, while 'List' in alternative signature has 0 of them")
|
||||
@KotlinSignature("fun <A, B : Runnable> foo(a : A, b : List<out B>) where B : List")
|
||||
@KotlinSignature("fun <A, B : Runnable> foo(a : A, b : List<B>) where B : List")
|
||||
public <A, B extends Runnable & List<Cloneable>> void foo(A a, List<? extends B> b) {
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,6 +3,6 @@ package test
|
||||
import java.util.*
|
||||
|
||||
public open class WrongTypeParameterBoundStructure2 : Object() {
|
||||
public open fun <erased A, erased B : Runnable?> foo(p0 : A?, p1 : List<out B>?) where B : List<Cloneable?>? {
|
||||
public open fun <erased A, erased B : Runnable?> foo(p0 : A?, p1 : List<B>?) where B : List<Cloneable?>? {
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,5 +2,5 @@ namespace test
|
||||
|
||||
public open class test.WrongTypeParameterBoundStructure2 : java.lang.Object {
|
||||
public final /*constructor*/ fun <init>(): test.WrongTypeParameterBoundStructure2
|
||||
public open fun </*0*/ A : jet.Any?, /*1*/ B : java.lang.Runnable? & jet.List<java.lang.Cloneable?>?>foo(/*0*/ p0: A?, /*1*/ p1: jet.List<out B>?): jet.Tuple0
|
||||
public open fun </*0*/ A : jet.Any?, /*1*/ B : java.lang.Runnable? & jet.List<java.lang.Cloneable?>?>foo(/*0*/ p0: A?, /*1*/ p1: jet.List<B>?): jet.Tuple0
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError;
|
||||
|
||||
public class WrongTypeParametersCount {
|
||||
@ExpectLoadError("Method signature has 2 type parameters, but alternative signature has 3")
|
||||
@KotlinSignature("fun <A, B, C> foo(a : A, b : List<out B>)")
|
||||
@KotlinSignature("fun <A, B, C> foo(a : A, b : List<B>)")
|
||||
public <A, B> void foo(A a, List<? extends B> b) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package test
|
||||
import java.util.*
|
||||
|
||||
public open class WrongTypeParametersCount : Object() {
|
||||
public open fun <erased A, erased B> foo(p0 : A?, p1 : List<out B>?) {
|
||||
public open fun <erased A, erased B> foo(p0 : A?, p1 : List<B>?) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ namespace test
|
||||
|
||||
public open class test.WrongTypeParametersCount : java.lang.Object {
|
||||
public final /*constructor*/ fun <init>(): test.WrongTypeParametersCount
|
||||
public open fun </*0*/ A : jet.Any?, /*1*/ B : jet.Any?>foo(/*0*/ p0: A?, /*1*/ p1: jet.List<out B>?): jet.Tuple0
|
||||
public open fun </*0*/ A : jet.Any?, /*1*/ B : jet.Any?>foo(/*0*/ p0: A?, /*1*/ p1: jet.List<B>?): jet.Tuple0
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package test;
|
||||
|
||||
import java.lang.Number;
|
||||
import java.util.*;
|
||||
|
||||
import jet.runtime.typeinfo.KotlinSignature;
|
||||
@@ -7,8 +8,8 @@ import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError;
|
||||
|
||||
public class WrongTypeVariance {
|
||||
@ExpectLoadError("Variance mismatch, actual: out, in alternative signature: ")
|
||||
@KotlinSignature("fun copy(a : List<out Number>, b : List<Number>) : MutableList<Number>")
|
||||
public List<Number> copy(List<? extends Number> from, List<? extends Number> to) {
|
||||
@KotlinSignature("fun copy(a : Array<out Number>, b : Array<Number>) : MutableList<Number>")
|
||||
public List<Number> copy(Number[] from, Number[] to) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package test
|
||||
import java.util.*
|
||||
|
||||
public open class WrongTypeVariance : Object() {
|
||||
public open fun copy(p0 : List<out jet.Number?>?, p1 : List<out jet.Number?>?) : MutableList<jet.Number?>? {
|
||||
public open fun copy(p0 : Array<out Number?>?, p1 : Array<out Number?>?) : MutableList<Number?>? {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ namespace test
|
||||
|
||||
public open class test.WrongTypeVariance : java.lang.Object {
|
||||
public final /*constructor*/ fun <init>(): test.WrongTypeVariance
|
||||
public open fun copy(/*0*/ p0: jet.List<out jet.Number?>?, /*1*/ p1: jet.List<out jet.Number?>?): jet.MutableList<jet.Number?>?
|
||||
public open fun copy(/*0*/ p0: jet.Array<out jet.Number?>?, /*1*/ p1: jet.Array<out jet.Number?>?): jet.MutableList<jet.Number?>?
|
||||
}
|
||||
|
||||
@@ -139,6 +139,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
doTest("compiler/testData/loadJava/MyException.java");
|
||||
}
|
||||
|
||||
@TestMetadata("RemoveRedundantProjectionKind.java")
|
||||
public void testRemoveRedundantProjectionKind() throws Exception {
|
||||
doTest("compiler/testData/loadJava/RemoveRedundantProjectionKind.java");
|
||||
}
|
||||
|
||||
@TestMetadata("Simple.java")
|
||||
public void testSimple() throws Exception {
|
||||
doTest("compiler/testData/loadJava/Simple.java");
|
||||
|
||||
+5
@@ -1029,6 +1029,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
doTestSinglePackage("compiler/testData/loadJava/MyException.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("RemoveRedundantProjectionKind.kt")
|
||||
public void testRemoveRedundantProjectionKind() throws Exception {
|
||||
doTestSinglePackage("compiler/testData/loadJava/RemoveRedundantProjectionKind.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
doTestSinglePackage("compiler/testData/loadJava/Simple.kt");
|
||||
|
||||
Reference in New Issue
Block a user