Loading generic interfaces with upper bounds.

This commit is contained in:
Evgeny Gerashchenko
2013-03-21 21:52:19 +04:00
parent dea7ef77ec
commit 0422253943
6 changed files with 49 additions and 5 deletions
@@ -94,11 +94,17 @@ public class SingleAbstractMethodUtils {
JetType returnType = typeParametersSubstitutor.substitute(klass.getDefaultType(), Variance.OUT_VARIANCE);
assert returnType != null : "couldn't substitute type: " + returnType + ", substitutor = " + typeParametersSubstitutor;
for (TypeParameterDescriptorImpl typeParameter : traitToFunTypeParameters.values()) {
// TODO copy substituted upper bound
// TODO consider recursive upper bound
typeParameter.addDefaultUpperBound();
typeParameter.setInitialized();
for (Map.Entry<TypeParameterDescriptor, TypeParameterDescriptorImpl> mapEntry : traitToFunTypeParameters.entrySet()) {
TypeParameterDescriptor traitTypeParameter = mapEntry.getKey();
TypeParameterDescriptorImpl funTypeParameter = mapEntry.getValue();
for (JetType upperBound : traitTypeParameter.getUpperBounds()) {
JetType upperBoundSubstituted = typeParametersSubstitutor.substitute(upperBound, Variance.INVARIANT);
assert upperBoundSubstituted != null : "couldn't substitute type: " + upperBound + ", substitutor = " + typeParametersSubstitutor;
funTypeParameter.addUpperBound(upperBoundSubstituted);
}
funTypeParameter.setInitialized();
}
result.initialize(
@@ -0,0 +1,7 @@
package test;
import java.util.List;
public interface GenericInterfaceParameterWithSelfBound<T extends GenericInterfaceParameterWithSelfBound<T>> {
T method(T t);
}
@@ -0,0 +1,7 @@
package test
public /*synthesized*/ fun </*0*/ T : test.GenericInterfaceParameterWithSelfBound<T>?> GenericInterfaceParameterWithSelfBound(/*0*/ function : (T?) -> T?) : test.GenericInterfaceParameterWithSelfBound<T>
public trait GenericInterfaceParameterWithSelfBound</*0*/ T : test.GenericInterfaceParameterWithSelfBound<T>?> : java.lang.Object {
public abstract fun method(/*0*/ p0 : T?) : T?
}
@@ -0,0 +1,7 @@
package test;
import java.util.List;
public interface GenericInterfaceParametersWithBounds<A extends Comparable<A> & Cloneable, B extends List<A>> {
void method(A[] a, B b);
}
@@ -0,0 +1,7 @@
package test
public /*synthesized*/ fun </*0*/ A, /*1*/ B : jet.List<A>?> GenericInterfaceParametersWithBounds(/*0*/ function : (jet.Array<out A>?, B?) -> jet.Unit) : test.GenericInterfaceParametersWithBounds<A, B> where A : jet.Comparable<A>?, A : java.lang.Cloneable?
public trait GenericInterfaceParametersWithBounds</*0*/ A, /*1*/ B : jet.List<A>?> : java.lang.Object where A : jet.Comparable<A>?, A : java.lang.Cloneable? {
public abstract fun method(/*0*/ p0 : jet.Array<out A>?, /*1*/ p1 : B?) : jet.Unit
}
@@ -1140,6 +1140,16 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTestCompiledJava("compiler/testData/loadJava/compiledJava/singleAbstractMethod/FilenameFilter.java");
}
@TestMetadata("GenericInterfaceParameterWithSelfBound.java")
public void testGenericInterfaceParameterWithSelfBound() throws Exception {
doTestCompiledJava("compiler/testData/loadJava/compiledJava/singleAbstractMethod/GenericInterfaceParameterWithSelfBound.java");
}
@TestMetadata("GenericInterfaceParametersWithBounds.java")
public void testGenericInterfaceParametersWithBounds() throws Exception {
doTestCompiledJava("compiler/testData/loadJava/compiledJava/singleAbstractMethod/GenericInterfaceParametersWithBounds.java");
}
@TestMetadata("GenericMethodParameters.java")
public void testGenericMethodParameters() throws Exception {
doTestCompiledJava("compiler/testData/loadJava/compiledJava/singleAbstractMethod/GenericMethodParameters.java");