Write vararg flag on value parameters
This commit is contained in:
@@ -47,7 +47,6 @@ import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -401,6 +400,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
JetValueParameterAnnotationWriter av = JetValueParameterAnnotationWriter.visitParameterAnnotation(mv, i + start);
|
||||
av.writeName(parameterDescriptor.getName().getName());
|
||||
av.writeHasDefaultValue(parameterDescriptor.declaresDefaultValue());
|
||||
av.writeVararg(parameterDescriptor.getVarargElementType() != null);
|
||||
if (kotlinParameterTypes.get(i) != null) {
|
||||
av.writeType(kotlinParameterTypes.get(i + start).getKotlinSignature());
|
||||
}
|
||||
|
||||
@@ -1099,6 +1099,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
JetValueParameterAnnotationWriter.visitParameterAnnotation(mv, i);
|
||||
jetValueParameterAnnotation.writeName(valueParameter.getName().getName());
|
||||
jetValueParameterAnnotation.writeHasDefaultValue(valueParameter.declaresDefaultValue());
|
||||
jetValueParameterAnnotation.writeVararg(valueParameter.getVarargElementType() != null);
|
||||
jetValueParameterAnnotation.writeType(constructorMethod.getKotlinParameterType(i));
|
||||
jetValueParameterAnnotation.visitEnd();
|
||||
++i;
|
||||
|
||||
+6
@@ -58,4 +58,10 @@ public class JetValueParameterAnnotationWriter {
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeVararg(boolean vararg) {
|
||||
if (vararg) {
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_VARARG, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class JvmAbi {
|
||||
* This constant is used to identify binary format (class file) versions
|
||||
* If you change class file metadata format and/or naming conventions, please increase this number
|
||||
*/
|
||||
public static final int VERSION = 0;
|
||||
public static final int VERSION = 1;
|
||||
|
||||
public static final String TRAIT_IMPL_CLASS_NAME = "$TImpl";
|
||||
public static final String TRAIT_IMPL_SUFFIX = "$" + TRAIT_IMPL_CLASS_NAME;
|
||||
|
||||
@@ -26,6 +26,7 @@ public class JvmStdlibNames {
|
||||
public static final String JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD = "hasDefaultValue";
|
||||
public static final String JET_VALUE_PARAMETER_TYPE_FIELD = "type";
|
||||
public static final String JET_VALUE_PARAMETER_RECEIVER_FIELD = "receiver";
|
||||
public static final String JET_VALUE_PARAMETER_VARARG = "vararg";
|
||||
|
||||
|
||||
public static final JvmClassName JET_TYPE_PARAMETER = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetTypeParameter");
|
||||
|
||||
+8
-1
@@ -33,6 +33,7 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
|
||||
private String type;
|
||||
private boolean receiver;
|
||||
private boolean hasDefaultValue;
|
||||
private boolean vararg;
|
||||
|
||||
private JetValueParameterAnnotation(@Nullable PsiAnnotation psiAnnotation) {
|
||||
super(psiAnnotation);
|
||||
@@ -44,6 +45,7 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
|
||||
type = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, "");
|
||||
receiver = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, false);
|
||||
hasDefaultValue = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, false);
|
||||
vararg = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_VARARG, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -67,7 +69,12 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
|
||||
checkInitialized();
|
||||
return hasDefaultValue;
|
||||
}
|
||||
|
||||
|
||||
public boolean vararg() {
|
||||
checkInitialized();
|
||||
return vararg;
|
||||
}
|
||||
|
||||
public static JetValueParameterAnnotation get(PsiParameter psiParameter) {
|
||||
final PsiAnnotation annotation =
|
||||
JavaAnnotationResolver.findOwnAnnotation(psiParameter, JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().getFqName());
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ public final class JavaValueParameterResolver {
|
||||
}
|
||||
|
||||
JetType varargElementType;
|
||||
if (psiType instanceof PsiEllipsisType) {
|
||||
if (psiType instanceof PsiEllipsisType || parameter.getJetValueParameter().vararg()) {
|
||||
varargElementType = KotlinBuiltIns.getInstance().getArrayElementType(TypeUtils.makeNotNullable(outType));
|
||||
outType = TypeUtils.makeNotNullable(outType);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
WARNING: $TESTDATA_DIR$/wrongAbiVersion.kt: (3, 9) Parameter 'x' is never used
|
||||
ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/wrong/WrongPackage.java: (3, 1) Class 'wrong.WrongPackage' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 0
|
||||
ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/ClassWithWrongAbiVersion.java: (3, 1) Class 'ClassWithWrongAbiVersion' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 0
|
||||
ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/wrong/WrongPackage.java: (3, 1) Class 'wrong.WrongPackage' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 1
|
||||
ERROR: $TESTDATA_DIR$/wrongAbiVersionLib/ClassWithWrongAbiVersion.java: (3, 1) Class 'ClassWithWrongAbiVersion' was compiled with an incompatible version of Kotlin. Its ABI version is -1, expected ABI version is 1
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
class A(vararg a: Int, f: () -> Unit) {}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
internal final class A {
|
||||
/*primary*/ public constructor A(/*0*/ vararg a : jet.Int /*jet.IntArray*/, /*1*/ f : () -> Unit)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun f(vararg t: Int, f: () -> Unit) {}
|
||||
|
||||
fun f(vararg t: String, f: () -> Unit) {}
|
||||
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
internal fun f(/*0*/ vararg t : jet.String /*jet.Array<jet.String>*/, /*1*/ f : () -> Unit) : Unit
|
||||
internal fun f(/*0*/ vararg t : jet.Int /*jet.IntArray*/, /*1*/ f : () -> Unit) : Unit
|
||||
@@ -256,6 +256,7 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/constructor")
|
||||
@InnerTestClasses({Constructor.Vararg.class})
|
||||
public static class Constructor extends AbstractLoadCompiledKotlinTest {
|
||||
public void testAllFilesPresentInConstructor() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/constructor"), "kt", true);
|
||||
@@ -286,11 +287,6 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
doTest("compiler/testData/loadKotlin/constructor/ConstructorCollectionParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorVararg.kt")
|
||||
public void testConstructorVararg() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/constructor/ConstructorVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorWithTwoDefArgs.kt")
|
||||
public void testConstructorWithTwoDefArgs() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/constructor/ConstructorWithTwoDefArgs.kt");
|
||||
@@ -331,6 +327,30 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
doTest("compiler/testData/loadKotlin/constructor/PrivateConstructor1WithParamDefaultValue.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/constructor/vararg")
|
||||
public static class Vararg extends AbstractLoadCompiledKotlinTest {
|
||||
public void testAllFilesPresentInVararg() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/constructor/vararg"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorNonLastVararg.kt")
|
||||
public void testConstructorNonLastVararg() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/constructor/vararg/ConstructorNonLastVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorVararg.kt")
|
||||
public void testConstructorVararg() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/constructor/vararg/ConstructorVararg.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Constructor");
|
||||
suite.addTestSuite(Constructor.class);
|
||||
suite.addTestSuite(Vararg.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/dataClass")
|
||||
@@ -377,7 +397,7 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/fun")
|
||||
@InnerTestClasses({Fun.GenericWithTypeVariables.class, Fun.GenericWithoutTypeVariables.class, Fun.NonGeneric.class})
|
||||
@InnerTestClasses({Fun.GenericWithTypeVariables.class, Fun.GenericWithoutTypeVariables.class, Fun.NonGeneric.class, Fun.Vararg.class})
|
||||
public static class Fun extends AbstractLoadCompiledKotlinTest {
|
||||
public void testAllFilesPresentInFun() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/fun"), "kt", true);
|
||||
@@ -567,12 +587,26 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/fun/vararg")
|
||||
public static class Vararg extends AbstractLoadCompiledKotlinTest {
|
||||
public void testAllFilesPresentInVararg() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/fun/vararg"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("nonLastVararg.kt")
|
||||
public void testNonLastVararg() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/fun/vararg/nonLastVararg.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Fun");
|
||||
suite.addTestSuite(Fun.class);
|
||||
suite.addTestSuite(GenericWithTypeVariables.class);
|
||||
suite.addTestSuite(GenericWithoutTypeVariables.class);
|
||||
suite.addTestSuite(NonGeneric.class);
|
||||
suite.addTestSuite(Vararg.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
@@ -952,7 +986,7 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
suite.addTestSuite(Class.class);
|
||||
suite.addTestSuite(ClassFun.class);
|
||||
suite.addTestSuite(ClassObject.class);
|
||||
suite.addTestSuite(Constructor.class);
|
||||
suite.addTest(Constructor.innerSuite());
|
||||
suite.addTestSuite(DataClass.class);
|
||||
suite.addTest(Fun.innerSuite());
|
||||
suite.addTestSuite(Prop.class);
|
||||
|
||||
+41
-7
@@ -258,6 +258,7 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/constructor")
|
||||
@InnerTestClasses({Constructor.Vararg.class})
|
||||
public static class Constructor extends AbstractLazyResolveNamespaceComparingTest {
|
||||
public void testAllFilesPresentInConstructor() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/constructor"), "kt", true);
|
||||
@@ -288,11 +289,6 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/ConstructorCollectionParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorVararg.kt")
|
||||
public void testConstructorVararg() throws Exception {
|
||||
doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/ConstructorVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorWithTwoDefArgs.kt")
|
||||
public void testConstructorWithTwoDefArgs() throws Exception {
|
||||
doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/ConstructorWithTwoDefArgs.kt");
|
||||
@@ -333,6 +329,30 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/PrivateConstructor1WithParamDefaultValue.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/constructor/vararg")
|
||||
public static class Vararg extends AbstractLazyResolveNamespaceComparingTest {
|
||||
public void testAllFilesPresentInVararg() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/constructor/vararg"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorNonLastVararg.kt")
|
||||
public void testConstructorNonLastVararg() throws Exception {
|
||||
doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/vararg/ConstructorNonLastVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorVararg.kt")
|
||||
public void testConstructorVararg() throws Exception {
|
||||
doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/vararg/ConstructorVararg.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Constructor");
|
||||
suite.addTestSuite(Constructor.class);
|
||||
suite.addTestSuite(Vararg.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/dataClass")
|
||||
@@ -379,7 +399,7 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/fun")
|
||||
@InnerTestClasses({Fun.GenericWithTypeVariables.class, Fun.GenericWithoutTypeVariables.class, Fun.NonGeneric.class})
|
||||
@InnerTestClasses({Fun.GenericWithTypeVariables.class, Fun.GenericWithoutTypeVariables.class, Fun.NonGeneric.class, Fun.Vararg.class})
|
||||
public static class Fun extends AbstractLazyResolveNamespaceComparingTest {
|
||||
public void testAllFilesPresentInFun() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/fun"), "kt", true);
|
||||
@@ -569,12 +589,26 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/fun/vararg")
|
||||
public static class Vararg extends AbstractLazyResolveNamespaceComparingTest {
|
||||
public void testAllFilesPresentInVararg() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadKotlin/fun/vararg"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("nonLastVararg.kt")
|
||||
public void testNonLastVararg() throws Exception {
|
||||
doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/fun/vararg/nonLastVararg.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Fun");
|
||||
suite.addTestSuite(Fun.class);
|
||||
suite.addTestSuite(GenericWithTypeVariables.class);
|
||||
suite.addTestSuite(GenericWithoutTypeVariables.class);
|
||||
suite.addTestSuite(NonGeneric.class);
|
||||
suite.addTestSuite(Vararg.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
@@ -954,7 +988,7 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
suite.addTestSuite(Class.class);
|
||||
suite.addTestSuite(ClassFun.class);
|
||||
suite.addTestSuite(ClassObject.class);
|
||||
suite.addTestSuite(Constructor.class);
|
||||
suite.addTest(Constructor.innerSuite());
|
||||
suite.addTestSuite(DataClass.class);
|
||||
suite.addTest(Fun.innerSuite());
|
||||
suite.addTestSuite(Prop.class);
|
||||
|
||||
@@ -48,4 +48,12 @@ public @interface JetValueParameter {
|
||||
* @return type unless Java type is correct Kotlin type.
|
||||
*/
|
||||
String type() default "";
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if this parameter is a vararg
|
||||
*
|
||||
* NOTE: a method may have a vararg parameter in Kotlin and not be marked as Opcodes.ACC_VARARGS, e.g.
|
||||
* fun foo(vararg x: Int, f: () -> Unit)
|
||||
*/
|
||||
boolean vararg() default false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user