KT-4770 Javac fails against Kotlin inner class

#KT-4770 fixed
This commit is contained in:
Evgeny Gerashchenko
2014-03-27 23:25:32 +04:00
parent bcc6843835
commit 829cd95469
11 changed files with 75 additions and 10 deletions
@@ -157,8 +157,8 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
JvmMethodParameterKind kind = kotlinParameterTypes.get(i).getKind();
if (kind == JvmMethodParameterKind.ENUM_NAME || kind == JvmMethodParameterKind.ENUM_ORDINAL) {
markEnumConstructorParameterAsSynthetic(mv, i);
if (kind.isSkippedInGenericSignature()) {
markEnumOrInnerConstructorParameterAsSynthetic(mv, i);
continue;
}
@@ -181,8 +181,8 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
JvmMethodParameterKind kind = kotlinParameterTypes.get(i).getKind();
if (kind == JvmMethodParameterKind.ENUM_NAME || kind == JvmMethodParameterKind.ENUM_ORDINAL) {
markEnumConstructorParameterAsSynthetic(mv, i);
if (kind.isSkippedInGenericSignature()) {
markEnumOrInnerConstructorParameterAsSynthetic(mv, i);
continue;
}
@@ -223,7 +223,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
}
}
private void markEnumConstructorParameterAsSynthetic(MethodVisitor mv, int i) {
private void markEnumOrInnerConstructorParameterAsSynthetic(MethodVisitor mv, int i) {
// IDEA's ClsPsi builder fails to annotate synthetic parameters
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return;
@@ -183,8 +183,8 @@ public class BothSignatureWriter {
public void writeParameterType(JvmMethodParameterKind parameterKind) {
// This magic mimics the behavior of javac that enum constructor have these synthetic parameters in erased signature, but doesn't
// have them in generic signature. IDEA relies on this behavior.
if (parameterKind == JvmMethodParameterKind.ENUM_NAME || parameterKind == JvmMethodParameterKind.ENUM_ORDINAL) {
// have them in generic signature. IDEA, javac and their friends rely on this behavior.
if (parameterKind.isSkippedInGenericSignature()) {
generic = true;
// pushing dummy visitor, because we don't want these parameters to appear in generic JVM signature
@@ -16,6 +16,8 @@
package org.jetbrains.jet.codegen.signature;
import java.util.EnumSet;
public enum JvmMethodParameterKind {
VALUE,
THIS,
@@ -24,5 +26,11 @@ public enum JvmMethodParameterKind {
SHARED_VAR,
ENUM_NAME,
ENUM_ORDINAL,
SUPER_CALL_PARAM
SUPER_CALL_PARAM;
private static final EnumSet<JvmMethodParameterKind> SKIPPED_IN_GENERIC_SIGNATURE = EnumSet.of(OUTER, ENUM_NAME, ENUM_ORDINAL);
public boolean isSkippedInGenericSignature() {
return SKIPPED_IN_GENERIC_SIGNATURE.contains(this);
}
}
@@ -0,0 +1,6 @@
package test;
class InnerClass {
Outer.Inner1 field1;
Outer.Inner2 field2;
}
@@ -0,0 +1,6 @@
package test
class Outer {
inner class Inner1
inner class Inner2(param: String)
}
@@ -0,0 +1,8 @@
package test;
class InnerClassConstructors {
public static void main(String[] args) {
new Outer().new InnerGeneric(new java.util.ArrayList<String>());
new Outer().new InnerPrimitive(1);
}
}
@@ -0,0 +1,7 @@
package test
class Outer {
inner class InnerGeneric(param: List<String>)
inner class InnerPrimitive(param: Int)
}
@@ -0,0 +1,8 @@
package test;
class InnerClassOfGeneric {
public static void main(String[] args) {
new Outer<String>().new Inner(new java.util.ArrayList<String>());
new Outer<String>().new InnerSimple();
}
}
@@ -0,0 +1,7 @@
package test
class Outer<T> {
inner class Inner(list: List<T>)
inner class InnerSimple()
}
@@ -146,8 +146,8 @@ public class AnnotationGenTest extends CodegenTestCase {
Class<?> inner = outer.getDeclaredClasses()[0];
Constructor constructor = inner.getDeclaredConstructor(outer, int.class);
assertNotNull(constructor);
// Get annotations for first real parameter
Annotation[] annotations = constructor.getParameterAnnotations()[1];
// Get annotations for first parameter
Annotation[] annotations = constructor.getParameterAnnotations()[0];
assertNotNull(getDeprecatedAnnotationFromList(annotations));
}
@@ -73,6 +73,21 @@ public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAg
doTest("compiler/testData/compileJavaAgainstKotlin/class/ImplementsMapPP.kt");
}
@TestMetadata("InnerClass.kt")
public void testInnerClass() throws Exception {
doTest("compiler/testData/compileJavaAgainstKotlin/class/InnerClass.kt");
}
@TestMetadata("InnerClassConstructors.kt")
public void testInnerClassConstructors() throws Exception {
doTest("compiler/testData/compileJavaAgainstKotlin/class/InnerClassConstructors.kt");
}
@TestMetadata("InnerClassOfGeneric.kt")
public void testInnerClassOfGeneric() throws Exception {
doTest("compiler/testData/compileJavaAgainstKotlin/class/InnerClassOfGeneric.kt");
}
@TestMetadata("kt3561.kt")
public void testKt3561() throws Exception {
doTest("compiler/testData/compileJavaAgainstKotlin/class/kt3561.kt");