Supported star projection in alternative signatures.
This commit is contained in:
+18
-5
@@ -118,11 +118,23 @@ class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
||||
|
||||
List<TypeProjection> altArguments = new ArrayList<TypeProjection>();
|
||||
for (int i = 0, size = arguments.size(); i < size; i++) {
|
||||
JetTypeElement argumentAlternativeTypeElement = type.getTypeArgumentsAsTypes().get(i).getTypeElement();
|
||||
JetTypeReference typeReference = type.getTypeArgumentsAsTypes().get(i);
|
||||
|
||||
if (typeReference == null) {
|
||||
// star projection
|
||||
assert type instanceof JetUserType
|
||||
&& ((JetUserType) type).getTypeArguments().get(i).getProjectionKind() == JetProjectionKind.STAR;
|
||||
|
||||
altArguments.add(arguments.get(i));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
JetTypeElement argumentAlternativeTypeElement = typeReference.getTypeElement();
|
||||
assert argumentAlternativeTypeElement != null;
|
||||
|
||||
TypeProjection argument = arguments.get(i);
|
||||
JetType alternativeType = computeType(argumentAlternativeTypeElement, argument.getType(), originalToAltTypeParameters);
|
||||
JetType alternativeArgumentType = computeType(argumentAlternativeTypeElement, argument.getType(), originalToAltTypeParameters);
|
||||
Variance projectionKind = argument.getProjectionKind();
|
||||
Variance altProjectionKind;
|
||||
if (type instanceof JetUserType) {
|
||||
@@ -135,18 +147,19 @@ class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
||||
altProjectionKind = Variance.OUT_VARIANCE;
|
||||
break;
|
||||
case STAR:
|
||||
throw new AlternativeSignatureMismatchException("Star projection is not available in alternative signatures");
|
||||
throw new IllegalStateException("star projection should have been processed above");
|
||||
default:
|
||||
altProjectionKind = Variance.INVARIANT;
|
||||
}
|
||||
if (altProjectionKind != projectionKind && projectionKind != Variance.INVARIANT) {
|
||||
throw new AlternativeSignatureMismatchException("Variance mismatch, actual: %s, in alternative signature: %s", projectionKind, altProjectionKind);
|
||||
throw new AlternativeSignatureMismatchException("Variance mismatch, actual: %s, in alternative signature: %s",
|
||||
projectionKind, altProjectionKind);
|
||||
}
|
||||
}
|
||||
else {
|
||||
altProjectionKind = projectionKind;
|
||||
}
|
||||
altArguments.add(new TypeProjection(altProjectionKind, alternativeType));
|
||||
altArguments.add(new TypeProjection(altProjectionKind, alternativeArgumentType));
|
||||
}
|
||||
|
||||
TypeConstructor typeConstructor;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package test;
|
||||
|
||||
import jet.runtime.typeinfo.KotlinSignature;
|
||||
|
||||
public final class StarProjection {
|
||||
@KotlinSignature("fun foo(): MyClass<*>")
|
||||
public final MyClass<?> foo() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public interface MyClass<T extends CharSequence> {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
public final class StarProjection: Object() {
|
||||
public final fun foo(): MyClass<*> = throw UnsupportedOperationException()
|
||||
|
||||
public trait MyClass<T: CharSequence?>: Object
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace test
|
||||
|
||||
public final class test.StarProjection : java.lang.Object {
|
||||
public final /*constructor*/ fun <init>(): test.StarProjection
|
||||
public final fun foo(): test.StarProjection.MyClass<out jet.CharSequence?>
|
||||
public abstract trait test.StarProjection.MyClass</*0*/ T : jet.CharSequence?> : java.lang.Object {
|
||||
}
|
||||
}
|
||||
@@ -310,6 +310,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
doTest("compiler/testData/loadJava/kotlinSignature/PropertySimpleType.java");
|
||||
}
|
||||
|
||||
@TestMetadata("StarProjection.java")
|
||||
public void testStarProjection() throws Exception {
|
||||
doTest("compiler/testData/loadJava/kotlinSignature/StarProjection.java");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadJava/kotlinSignature/error")
|
||||
public static class Error extends AbstractLoadJavaTest {
|
||||
@TestMetadata("AddingNullability.java")
|
||||
|
||||
+5
@@ -1200,6 +1200,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/PropertySimpleType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("StarProjection.kt")
|
||||
public void testStarProjection() throws Exception {
|
||||
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/StarProjection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadJava/kotlinSignature/error")
|
||||
public static class Error extends AbstractLazyResolveNamespaceComparingTest {
|
||||
@TestMetadata("AddingNullability.kt")
|
||||
|
||||
Reference in New Issue
Block a user