Fixed mapping generic type with multiple bounds from Java to Kotlin.

#KT-3480 fixed
This commit is contained in:
Evgeny Gerashchenko
2014-01-22 17:16:12 +04:00
committed by Zalim Bashorov
parent e47c84f40f
commit d3570153ef
12 changed files with 67 additions and 8 deletions
@@ -282,7 +282,7 @@ public class JetTypeMapper extends BindingTraceAware {
if (descriptor instanceof TypeParameterDescriptor) {
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) descriptor;
Type type = mapType(typeParameterDescriptor.getUpperBoundsAsType(), kind);
Type type = mapType(typeParameterDescriptor.getUpperBounds().iterator().next(), kind);
if (signatureVisitor != null) {
signatureVisitor.writeTypeVariable(typeParameterDescriptor.getName(), type);
}
@@ -0,0 +1,7 @@
import java.util.*;
public class max {
public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) {
return Collections.max(coll);
}
}
@@ -0,0 +1,3 @@
fun box(): String {
return max.max(java.util.Arrays.asList("AK", "OK", "EK"))!!
}
@@ -0,0 +1,7 @@
import java.util.Collection;
public class unrelatedUpperBounds {
public static <T extends CharSequence & java.io.Serializable> T id(T p) {
return p;
}
}
@@ -0,0 +1,3 @@
fun box(): String {
return unrelatedUpperBounds.id("OK" as java.lang.String)!! as jet.String
}
@@ -0,0 +1,9 @@
package test;
import java.util.Collection;
public class Max {
public <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) {
throw new UnsupportedOperationException();
}
}
@@ -0,0 +1,7 @@
package test
public open class Max: Object() {
public open fun max<T : Any?>(p0 : Collection<T>?): T? where T : Comparable<T>? {
throw UnsupportedOperationException()
}
}
@@ -0,0 +1,6 @@
package test
public open class Max : java.lang.Object {
public constructor Max()
public open fun </*0*/ T> max(/*0*/ p0: jet.Collection<T>?): T? where T : jet.Comparable<T>?
}
@@ -16,17 +16,14 @@
package org.jetbrains.jet.codegen.generated;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.File;
import java.util.regex.Pattern;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@@ -137,6 +134,11 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
doTestWithJava("compiler/testData/codegen/boxWithJava/functions/constructor.kt");
}
@TestMetadata("max.kt")
public void testMax() throws Exception {
doTestWithJava("compiler/testData/codegen/boxWithJava/functions/max.kt");
}
@TestMetadata("referencesStaticInnerClassMethod.kt")
public void testReferencesStaticInnerClassMethod() throws Exception {
doTestWithJava("compiler/testData/codegen/boxWithJava/functions/referencesStaticInnerClassMethod.kt");
@@ -147,6 +149,11 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege
doTestWithJava("compiler/testData/codegen/boxWithJava/functions/referencesStaticInnerClassMethodL2.kt");
}
@TestMetadata("unrelatedUpperBounds.kt")
public void testUnrelatedUpperBounds() throws Exception {
doTestWithJava("compiler/testData/codegen/boxWithJava/functions/unrelatedUpperBounds.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxWithJava/innerClass")
@@ -1386,6 +1386,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTestCompiledJavaCompareWithKotlin("compiler/testData/loadJava/compiledJavaCompareWithKotlin/library/LoadIterator.java");
}
@TestMetadata("Max.java")
public void testMax() throws Exception {
doTestCompiledJavaCompareWithKotlin("compiler/testData/loadJava/compiledJavaCompareWithKotlin/library/Max.java");
}
}
@TestMetadata("compiler/testData/loadJava/compiledJavaCompareWithKotlin/modality")
@@ -2369,6 +2369,11 @@ public class LazyResolveRecursiveComparingTestGenerated extends AbstractLazyReso
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/library/LoadIterator.kt");
}
@TestMetadata("Max.kt")
public void testMax() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/library/Max.kt");
}
}
@TestMetadata("compiler/testData/loadJava/compiledJavaCompareWithKotlin/modality")
+2 -2
View File
@@ -1259,7 +1259,7 @@
<item name="java.util.Collections T max(java.util.Collection&lt;? extends T&gt;)">
<annotation name="org.jetbrains.annotations.NotNull"/>
<annotation name="jet.runtime.typeinfo.KotlinSignature">
<val name="value" val="&quot;fun &lt;T: Comparable&lt;T&gt;&gt; max(coll : Collection&lt;T&gt;) : T&quot;"/>
<val name="value" val="&quot;fun &lt;T: Any&gt; max(coll : Collection&lt;T&gt;) : T where T: Comparable&lt;T&gt;&quot;"/>
</annotation>
</item>
<item name="java.util.Collections T max(java.util.Collection&lt;? extends T&gt;) 0">
@@ -1281,7 +1281,7 @@
<item name="java.util.Collections T min(java.util.Collection&lt;? extends T&gt;)">
<annotation name="org.jetbrains.annotations.NotNull"/>
<annotation name="jet.runtime.typeinfo.KotlinSignature">
<val name="value" val="&quot;fun &lt;T: Comparable&lt;T&gt;&gt; min(coll : Collection&lt;T&gt;) : T&quot;"/>
<val name="value" val="&quot;fun &lt;T: Any&gt; min(coll : Collection&lt;T&gt;) : T where T: Comparable&lt;T&gt;&quot;"/>
</annotation>
</item>
<item name="java.util.Collections T min(java.util.Collection&lt;? extends T&gt;) 0">