Saving and loading projection kind of array element type in bytecode.

This commit is contained in:
Evgeny Gerashchenko
2012-11-20 16:45:44 +04:00
parent 21e97b408c
commit d37bdbc07d
16 changed files with 72 additions and 13 deletions
@@ -166,7 +166,7 @@ public class BothSignatureWriter {
writeClassEnd(); writeClassEnd();
return; return;
case Type.ARRAY: case Type.ARRAY:
writeArrayType(nullable); writeArrayType(nullable, Variance.INVARIANT);
writeAsmType(asmType.getElementType(), false, kotlinTypeName); writeAsmType(asmType.getElementType(), false, kotlinTypeName);
writeArrayEnd(); writeArrayEnd();
return; return;
@@ -235,9 +235,9 @@ public class BothSignatureWriter {
jetSignatureWriter.visitEnd(); jetSignatureWriter.visitEnd();
} }
public void writeArrayType(boolean nullable) { public void writeArrayType(boolean nullable, Variance projectionKind) {
push(signatureVisitor().visitArrayType()); push(signatureVisitor().visitArrayType());
jetSignatureWriter.visitArrayType(nullable); jetSignatureWriter.visitArrayType(nullable, toJetSignatureVariance(projectionKind));
if (jvmCurrentType == null) { if (jvmCurrentType == null) {
++jvmCurrentTypeArrayLevel; ++jvmCurrentTypeArrayLevel;
} }
@@ -266,10 +266,11 @@ public class JetTypeMapper extends BindingTraceAware {
if (jetType.getArguments().size() != 1) { if (jetType.getArguments().size() != 1) {
throw new UnsupportedOperationException("arrays must have one type argument"); throw new UnsupportedOperationException("arrays must have one type argument");
} }
JetType memberType = jetType.getArguments().get(0).getType(); TypeProjection memberProjection = jetType.getArguments().get(0);
JetType memberType = memberProjection.getType();
if (signatureVisitor != null) { if (signatureVisitor != null) {
signatureVisitor.writeArrayType(jetType.isNullable()); signatureVisitor.writeArrayType(jetType.isNullable(), memberProjection.getProjectionKind());
mapType(memberType, signatureVisitor, JetTypeMapperMode.TYPE_PARAMETER); mapType(memberType, signatureVisitor, JetTypeMapperMode.TYPE_PARAMETER);
signatureVisitor.writeArrayEnd(); signatureVisitor.writeArrayEnd();
} }
@@ -161,7 +161,7 @@ public abstract class JetTypeJetSignatureReader extends JetSignatureExceptionsAd
} }
@Override @Override
public JetSignatureVisitor visitArrayType(final boolean nullable) { public JetSignatureVisitor visitArrayType(final boolean nullable, final JetSignatureVariance wildcard) {
return new JetTypeJetSignatureReader(javaSemanticServices, kotlinBuiltIns, typeVariableResolver) { return new JetTypeJetSignatureReader(javaSemanticServices, kotlinBuiltIns, typeVariableResolver) {
@Override @Override
public void visitBaseType(char descriptor, boolean nullable) { public void visitBaseType(char descriptor, boolean nullable) {
@@ -178,7 +178,8 @@ public abstract class JetTypeJetSignatureReader extends JetSignatureExceptionsAd
@Override @Override
protected void done(@NotNull JetType jetType) { protected void done(@NotNull JetType jetType) {
JetType arrayType = TypeUtils.makeNullableAsSpecified(KotlinBuiltIns.getInstance().getArrayType(jetType), nullable); JetType arrayType = TypeUtils.makeNullableAsSpecified(KotlinBuiltIns.getInstance().getArrayType(
parseVariance(wildcard), jetType), nullable);
JetTypeJetSignatureReader.this.done(arrayType); JetTypeJetSignatureReader.this.done(arrayType);
} }
}; };
@@ -0,0 +1,3 @@
package test
fun nothing(): Array<in Number> = throw Exception()
@@ -0,0 +1,3 @@
namespace test
internal final fun nothing(): jet.Array<in jet.Number>
@@ -0,0 +1,3 @@
package test
fun nothing(): Array<out Number> = throw Exception()
@@ -0,0 +1,3 @@
namespace test
internal final fun nothing(): jet.Array<out jet.Number>
@@ -0,0 +1,3 @@
package test
fun <T> nothing(): Array<out T> = throw Exception()
@@ -0,0 +1,3 @@
namespace test
internal final fun </*0*/ T : jet.Any?>nothing(): jet.Array<out T>
@@ -724,6 +724,11 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
doTest("compiler/testData/loadKotlin/type/AnyQ.kt"); doTest("compiler/testData/loadKotlin/type/AnyQ.kt");
} }
@TestMetadata("ArrayOfInNumber.kt")
public void testArrayOfInNumber() throws Exception {
doTest("compiler/testData/loadKotlin/type/ArrayOfInNumber.kt");
}
@TestMetadata("ArrayOfInt.kt") @TestMetadata("ArrayOfInt.kt")
public void testArrayOfInt() throws Exception { public void testArrayOfInt() throws Exception {
doTest("compiler/testData/loadKotlin/type/ArrayOfInt.kt"); doTest("compiler/testData/loadKotlin/type/ArrayOfInt.kt");
@@ -734,6 +739,16 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
doTest("compiler/testData/loadKotlin/type/ArrayOfInteger.kt"); doTest("compiler/testData/loadKotlin/type/ArrayOfInteger.kt");
} }
@TestMetadata("ArrayOfOutNumber.kt")
public void testArrayOfOutNumber() throws Exception {
doTest("compiler/testData/loadKotlin/type/ArrayOfOutNumber.kt");
}
@TestMetadata("ArrayOfOutT.kt")
public void testArrayOfOutT() throws Exception {
doTest("compiler/testData/loadKotlin/type/ArrayOfOutT.kt");
}
@TestMetadata("ArrayOfString.kt") @TestMetadata("ArrayOfString.kt")
public void testArrayOfString() throws Exception { public void testArrayOfString() throws Exception {
doTest("compiler/testData/loadKotlin/type/ArrayOfString.kt"); doTest("compiler/testData/loadKotlin/type/ArrayOfString.kt");
@@ -726,6 +726,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
doTestSinglePackage("compiler/testData/loadKotlin/type/AnyQ.kt"); doTestSinglePackage("compiler/testData/loadKotlin/type/AnyQ.kt");
} }
@TestMetadata("ArrayOfInNumber.kt")
public void testArrayOfInNumber() throws Exception {
doTestSinglePackage("compiler/testData/loadKotlin/type/ArrayOfInNumber.kt");
}
@TestMetadata("ArrayOfInt.kt") @TestMetadata("ArrayOfInt.kt")
public void testArrayOfInt() throws Exception { public void testArrayOfInt() throws Exception {
doTestSinglePackage("compiler/testData/loadKotlin/type/ArrayOfInt.kt"); doTestSinglePackage("compiler/testData/loadKotlin/type/ArrayOfInt.kt");
@@ -736,6 +741,16 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
doTestSinglePackage("compiler/testData/loadKotlin/type/ArrayOfInteger.kt"); doTestSinglePackage("compiler/testData/loadKotlin/type/ArrayOfInteger.kt");
} }
@TestMetadata("ArrayOfOutNumber.kt")
public void testArrayOfOutNumber() throws Exception {
doTestSinglePackage("compiler/testData/loadKotlin/type/ArrayOfOutNumber.kt");
}
@TestMetadata("ArrayOfOutT.kt")
public void testArrayOfOutT() throws Exception {
doTestSinglePackage("compiler/testData/loadKotlin/type/ArrayOfOutT.kt");
}
@TestMetadata("ArrayOfString.kt") @TestMetadata("ArrayOfString.kt")
public void testArrayOfString() throws Exception { public void testArrayOfString() throws Exception {
doTestSinglePackage("compiler/testData/loadKotlin/type/ArrayOfString.kt"); doTestSinglePackage("compiler/testData/loadKotlin/type/ArrayOfString.kt");
@@ -75,7 +75,7 @@ public class JetSignatureAdapter implements JetSignatureVisitor {
} }
@Override @Override
public JetSignatureVisitor visitArrayType(boolean nullable) { public JetSignatureVisitor visitArrayType(boolean nullable, JetSignatureVariance wildcard) {
return this; return this;
} }
@@ -78,7 +78,7 @@ public class JetSignatureExceptionsAdapter implements JetSignatureVisitor {
} }
@Override @Override
public JetSignatureVisitor visitArrayType(boolean nullable) { public JetSignatureVisitor visitArrayType(boolean nullable, JetSignatureVariance wildcard) {
throw new IllegalStateException(); throw new IllegalStateException();
} }
@@ -172,7 +172,13 @@ public class JetSignatureReader {
return pos; return pos;
case '[': case '[':
return parseType(signature, pos, v.visitArrayType(nullable)); switch (c = signature.charAt(pos)) {
case '+':
case '-':
return parseType(signature, pos + 1, v.visitArrayType(nullable, JetSignatureVariance.parseVariance(c)));
default:
return parseType(signature, pos, v.visitArrayType(nullable, JetSignatureVariance.INVARIANT));
}
case 'T': case 'T':
end = signature.indexOf(';', pos); end = signature.indexOf(';', pos);
@@ -123,7 +123,7 @@ public interface JetSignatureVisitor {
* @return a non null visitor to visit the signature of the array element * @return a non null visitor to visit the signature of the array element
* type. * type.
*/ */
JetSignatureVisitor visitArrayType(boolean nullable); JetSignatureVisitor visitArrayType(boolean nullable, JetSignatureVariance wildcard);
/** /**
* Starts the visit of a signature corresponding to a class or interface * Starts the visit of a signature corresponding to a class or interface
@@ -157,9 +157,12 @@ public class JetSignatureWriter implements JetSignatureVisitor {
} }
@Override @Override
public JetSignatureWriter visitArrayType(boolean nullable) { public JetSignatureWriter visitArrayType(boolean nullable, JetSignatureVariance wildcard) {
visitNullabe(nullable); visitNullabe(nullable);
buf.append('['); buf.append('[');
if (wildcard != JetSignatureVariance.INVARIANT) {
buf.append(wildcard.getC());
}
return this; return this;
} }
@@ -195,7 +198,7 @@ public class JetSignatureWriter implements JetSignatureVisitor {
++argumentStack; ++argumentStack;
buf.append('<'); buf.append('<');
} }
if (variance.getC() != '=') { if (variance != JetSignatureVariance.INVARIANT) {
buf.append(variance.getC()); buf.append(variance.getC());
} }
return this; return this;