Processing vararg flag of parameter for primitives and wrappers.
#KT-2776 fixed
This commit is contained in:
+21
-6
@@ -240,19 +240,17 @@ public class SignaturesPropagationData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (someSupersVararg && originalVarargElementType == null) {
|
if (someSupersVararg && originalVarargElementType == null) {
|
||||||
assert KotlinBuiltIns.getInstance().isArray(originalType);
|
assert isArrayType(originalType);
|
||||||
|
|
||||||
// convert to vararg; replace Array<out Foo>? with Array<Foo>
|
// convert to vararg; replace Array<out Foo>? with Array<Foo>
|
||||||
JetType varargElementType = KotlinBuiltIns.getInstance().getArrayElementType(originalType);
|
JetType varargElementType = KotlinBuiltIns.getInstance().getArrayElementType(originalType);
|
||||||
return new VarargCheckResult(KotlinBuiltIns.getInstance().getArrayType(varargElementType), true);
|
return new VarargCheckResult(getArrayType(varargElementType, Variance.INVARIANT), true);
|
||||||
}
|
}
|
||||||
else if (someSupersNotVararg && originalVarargElementType != null) {
|
else if (someSupersNotVararg && originalVarargElementType != null) {
|
||||||
assert KotlinBuiltIns.getInstance().isArray(originalType);
|
assert isArrayType(originalType);
|
||||||
|
|
||||||
// convert to non-vararg; replace Array<Foo> with Array<out Foo>?
|
// convert to non-vararg; replace Array<Foo> with Array<out Foo>?
|
||||||
return new VarargCheckResult(
|
return new VarargCheckResult(TypeUtils.makeNullable(getArrayType(originalVarargElementType, Variance.OUT_VARIANCE)), false);
|
||||||
TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getArrayType(Variance.OUT_VARIANCE, originalVarargElementType)),
|
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new VarargCheckResult(originalType, originalVarargElementType != null);
|
return new VarargCheckResult(originalType, originalVarargElementType != null);
|
||||||
@@ -521,6 +519,23 @@ public class SignaturesPropagationData {
|
|||||||
return classifier;
|
return classifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isArrayType(@NotNull JetType type) {
|
||||||
|
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||||
|
return builtIns.isArray(type) || builtIns.isPrimitiveArray(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static JetType getArrayType(@NotNull JetType elementType, @NotNull Variance projectionKind) {
|
||||||
|
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||||
|
JetType primitiveArrayType = builtIns.getPrimitiveArrayJetTypeByPrimitiveJetType(elementType);
|
||||||
|
if (primitiveArrayType != null) {
|
||||||
|
return primitiveArrayType;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return builtIns.getArrayType(projectionKind, elementType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class VarargCheckResult {
|
private static class VarargCheckResult {
|
||||||
public final JetType parameterType;
|
public final JetType parameterType;
|
||||||
public final boolean isVararg;
|
public final boolean isVararg;
|
||||||
|
|||||||
@@ -726,14 +726,13 @@ public class KotlinBuiltIns {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getArrayElementType(@NotNull JetType arrayType) {
|
public JetType getArrayElementType(@NotNull JetType arrayType) {
|
||||||
// make non-null?
|
|
||||||
if (arrayType.getConstructor().getDeclarationDescriptor() == getArray()) {
|
if (arrayType.getConstructor().getDeclarationDescriptor() == getArray()) {
|
||||||
if (arrayType.getArguments().size() != 1) {
|
if (arrayType.getArguments().size() != 1) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
return arrayType.getArguments().get(0).getType();
|
return arrayType.getArguments().get(0).getType();
|
||||||
}
|
}
|
||||||
JetType primitiveType = jetArrayTypeToPrimitiveJetType.get(arrayType);
|
JetType primitiveType = jetArrayTypeToPrimitiveJetType.get(TypeUtils.makeNotNullable(arrayType));
|
||||||
if (primitiveType == null) {
|
if (primitiveType == null) {
|
||||||
throw new IllegalStateException("not array: " + arrayType);
|
throw new IllegalStateException("not array: " + arrayType);
|
||||||
}
|
}
|
||||||
@@ -823,6 +822,10 @@ public class KotlinBuiltIns {
|
|||||||
return getArray().equals(type.getConstructor().getDeclarationDescriptor());
|
return getArray().equals(type.getConstructor().getDeclarationDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPrimitiveArray(@NotNull JetType type) {
|
||||||
|
return jetArrayTypeToPrimitiveJetType.containsKey(TypeUtils.makeNotNullable(type));
|
||||||
|
}
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
|
|
||||||
public int getFunctionTraitCount() {
|
public int getFunctionTraitCount() {
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public interface InheritNotVarargInteger {
|
||||||
|
|
||||||
|
public interface Super {
|
||||||
|
void foo(Integer[] p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Sub extends Super {
|
||||||
|
void foo(Integer... p);
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public trait InheritNotVarargInteger: Object {
|
||||||
|
|
||||||
|
public trait Super: Object {
|
||||||
|
public fun foo(p0: Array<out Int?>?)
|
||||||
|
}
|
||||||
|
|
||||||
|
public trait Sub: Super {
|
||||||
|
override fun foo(p0: Array<out Int?>?)
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
namespace test
|
||||||
|
|
||||||
|
public abstract trait test.InheritNotVarargInteger : java.lang.Object {
|
||||||
|
public abstract trait test.InheritNotVarargInteger.Sub : test.InheritNotVarargInteger.Super {
|
||||||
|
public abstract override /*1*/ fun foo(/*0*/ p0: jet.Array<out jet.Int?>?): jet.Tuple0
|
||||||
|
}
|
||||||
|
public abstract trait test.InheritNotVarargInteger.Super : java.lang.Object {
|
||||||
|
public abstract fun foo(/*0*/ p0: jet.Array<out jet.Int?>?): jet.Tuple0
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public interface InheritNotVarargPrimitive {
|
||||||
|
|
||||||
|
public interface Super {
|
||||||
|
void foo(int[] p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Sub extends Super {
|
||||||
|
void foo(int... p);
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public trait InheritNotVarargPrimitive: Object {
|
||||||
|
|
||||||
|
public trait Super: Object {
|
||||||
|
public fun foo(p0: IntArray?)
|
||||||
|
}
|
||||||
|
|
||||||
|
public trait Sub: Super {
|
||||||
|
override fun foo(p0: IntArray?)
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
namespace test
|
||||||
|
|
||||||
|
public abstract trait test.InheritNotVarargPrimitive : java.lang.Object {
|
||||||
|
public abstract trait test.InheritNotVarargPrimitive.Sub : test.InheritNotVarargPrimitive.Super {
|
||||||
|
public abstract override /*1*/ fun foo(/*0*/ p0: jet.IntArray?): jet.Tuple0
|
||||||
|
}
|
||||||
|
public abstract trait test.InheritNotVarargPrimitive.Super : java.lang.Object {
|
||||||
|
public abstract fun foo(/*0*/ p0: jet.IntArray?): jet.Tuple0
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public interface InheritVarargInteger {
|
||||||
|
|
||||||
|
public interface Super {
|
||||||
|
void foo(Integer... p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Sub extends Super {
|
||||||
|
void foo(Integer[] p);
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public trait InheritVarargInteger: Object {
|
||||||
|
|
||||||
|
public trait Super: Object {
|
||||||
|
public fun foo(vararg p0: Int?)
|
||||||
|
}
|
||||||
|
|
||||||
|
public trait Sub: Super {
|
||||||
|
override fun foo(vararg p0: Int?)
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
namespace test
|
||||||
|
|
||||||
|
public abstract trait test.InheritVarargInteger : java.lang.Object {
|
||||||
|
public abstract trait test.InheritVarargInteger.Sub : test.InheritVarargInteger.Super {
|
||||||
|
public abstract override /*1*/ fun foo(/*0*/ vararg p0: jet.Int? /*jet.Array<jet.Int?>*/): jet.Tuple0
|
||||||
|
}
|
||||||
|
public abstract trait test.InheritVarargInteger.Super : java.lang.Object {
|
||||||
|
public abstract fun foo(/*0*/ vararg p0: jet.Int? /*jet.Array<jet.Int?>*/): jet.Tuple0
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public interface InheritVarargPrimitive {
|
||||||
|
|
||||||
|
public interface Super {
|
||||||
|
void foo(int... p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Sub extends Super {
|
||||||
|
void foo(int[] p);
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
public trait InheritVarargPrimitive: Object {
|
||||||
|
|
||||||
|
public trait Super: Object {
|
||||||
|
public fun foo(vararg p0: Int)
|
||||||
|
}
|
||||||
|
|
||||||
|
public trait Sub: Super {
|
||||||
|
override fun foo(vararg p0: Int)
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
namespace test
|
||||||
|
|
||||||
|
public abstract trait test.InheritVarargPrimitive : java.lang.Object {
|
||||||
|
public abstract trait test.InheritVarargPrimitive.Sub : test.InheritVarargPrimitive.Super {
|
||||||
|
public abstract override /*1*/ fun foo(/*0*/ vararg p0: jet.Int /*jet.IntArray*/): jet.Tuple0
|
||||||
|
}
|
||||||
|
public abstract trait test.InheritVarargPrimitive.Super : java.lang.Object {
|
||||||
|
public abstract fun foo(/*0*/ vararg p0: jet.Int /*jet.IntArray*/): jet.Tuple0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -471,11 +471,21 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
|||||||
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVararg.java");
|
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVararg.java");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InheritNotVarargInteger.java")
|
||||||
|
public void testInheritNotVarargInteger() throws Exception {
|
||||||
|
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVarargInteger.java");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("InheritNotVarargNotNull.java")
|
@TestMetadata("InheritNotVarargNotNull.java")
|
||||||
public void testInheritNotVarargNotNull() throws Exception {
|
public void testInheritNotVarargNotNull() throws Exception {
|
||||||
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVarargNotNull.java");
|
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVarargNotNull.java");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InheritNotVarargPrimitive.java")
|
||||||
|
public void testInheritNotVarargPrimitive() throws Exception {
|
||||||
|
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVarargPrimitive.java");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("InheritNullability.java")
|
@TestMetadata("InheritNullability.java")
|
||||||
public void testInheritNullability() throws Exception {
|
public void testInheritNullability() throws Exception {
|
||||||
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNullability.java");
|
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNullability.java");
|
||||||
@@ -496,11 +506,21 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
|||||||
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVararg.java");
|
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVararg.java");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InheritVarargInteger.java")
|
||||||
|
public void testInheritVarargInteger() throws Exception {
|
||||||
|
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVarargInteger.java");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("InheritVarargNotNull.java")
|
@TestMetadata("InheritVarargNotNull.java")
|
||||||
public void testInheritVarargNotNull() throws Exception {
|
public void testInheritVarargNotNull() throws Exception {
|
||||||
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVarargNotNull.java");
|
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVarargNotNull.java");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InheritVarargPrimitive.java")
|
||||||
|
public void testInheritVarargPrimitive() throws Exception {
|
||||||
|
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVarargPrimitive.java");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("MutableToReadOnly.java")
|
@TestMetadata("MutableToReadOnly.java")
|
||||||
public void testMutableToReadOnly() throws Exception {
|
public void testMutableToReadOnly() throws Exception {
|
||||||
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/MutableToReadOnly.java");
|
doTest("compiler/testData/loadJava/kotlinSignature/propagation/parameter/MutableToReadOnly.java");
|
||||||
|
|||||||
+20
@@ -1361,11 +1361,21 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
|||||||
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVararg.kt");
|
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVararg.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InheritNotVarargInteger.kt")
|
||||||
|
public void testInheritNotVarargInteger() throws Exception {
|
||||||
|
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVarargInteger.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("InheritNotVarargNotNull.kt")
|
@TestMetadata("InheritNotVarargNotNull.kt")
|
||||||
public void testInheritNotVarargNotNull() throws Exception {
|
public void testInheritNotVarargNotNull() throws Exception {
|
||||||
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVarargNotNull.kt");
|
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVarargNotNull.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InheritNotVarargPrimitive.kt")
|
||||||
|
public void testInheritNotVarargPrimitive() throws Exception {
|
||||||
|
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNotVarargPrimitive.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("InheritNullability.kt")
|
@TestMetadata("InheritNullability.kt")
|
||||||
public void testInheritNullability() throws Exception {
|
public void testInheritNullability() throws Exception {
|
||||||
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNullability.kt");
|
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritNullability.kt");
|
||||||
@@ -1386,11 +1396,21 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
|||||||
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVararg.kt");
|
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVararg.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InheritVarargInteger.kt")
|
||||||
|
public void testInheritVarargInteger() throws Exception {
|
||||||
|
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVarargInteger.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("InheritVarargNotNull.kt")
|
@TestMetadata("InheritVarargNotNull.kt")
|
||||||
public void testInheritVarargNotNull() throws Exception {
|
public void testInheritVarargNotNull() throws Exception {
|
||||||
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVarargNotNull.kt");
|
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVarargNotNull.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InheritVarargPrimitive.kt")
|
||||||
|
public void testInheritVarargPrimitive() throws Exception {
|
||||||
|
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/InheritVarargPrimitive.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("MutableToReadOnly.kt")
|
@TestMetadata("MutableToReadOnly.kt")
|
||||||
public void testMutableToReadOnly() throws Exception {
|
public void testMutableToReadOnly() throws Exception {
|
||||||
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/MutableToReadOnly.kt");
|
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/propagation/parameter/MutableToReadOnly.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user