KT-4770 Javac fails against Kotlin inner class
#KT-4770 fixed
This commit is contained in:
@@ -157,8 +157,8 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
|
|
||||||
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
|
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
|
||||||
JvmMethodParameterKind kind = kotlinParameterTypes.get(i).getKind();
|
JvmMethodParameterKind kind = kotlinParameterTypes.get(i).getKind();
|
||||||
if (kind == JvmMethodParameterKind.ENUM_NAME || kind == JvmMethodParameterKind.ENUM_ORDINAL) {
|
if (kind.isSkippedInGenericSignature()) {
|
||||||
markEnumConstructorParameterAsSynthetic(mv, i);
|
markEnumOrInnerConstructorParameterAsSynthetic(mv, i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,8 +181,8 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
|
|
||||||
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
|
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
|
||||||
JvmMethodParameterKind kind = kotlinParameterTypes.get(i).getKind();
|
JvmMethodParameterKind kind = kotlinParameterTypes.get(i).getKind();
|
||||||
if (kind == JvmMethodParameterKind.ENUM_NAME || kind == JvmMethodParameterKind.ENUM_ORDINAL) {
|
if (kind.isSkippedInGenericSignature()) {
|
||||||
markEnumConstructorParameterAsSynthetic(mv, i);
|
markEnumOrInnerConstructorParameterAsSynthetic(mv, i);
|
||||||
continue;
|
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
|
// IDEA's ClsPsi builder fails to annotate synthetic parameters
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return;
|
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return;
|
||||||
|
|
||||||
|
|||||||
@@ -183,8 +183,8 @@ public class BothSignatureWriter {
|
|||||||
|
|
||||||
public void writeParameterType(JvmMethodParameterKind parameterKind) {
|
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
|
// 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.
|
// have them in generic signature. IDEA, javac and their friends rely on this behavior.
|
||||||
if (parameterKind == JvmMethodParameterKind.ENUM_NAME || parameterKind == JvmMethodParameterKind.ENUM_ORDINAL) {
|
if (parameterKind.isSkippedInGenericSignature()) {
|
||||||
generic = true;
|
generic = true;
|
||||||
|
|
||||||
// pushing dummy visitor, because we don't want these parameters to appear in generic JVM signature
|
// pushing dummy visitor, because we don't want these parameters to appear in generic JVM signature
|
||||||
|
|||||||
+9
-1
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen.signature;
|
package org.jetbrains.jet.codegen.signature;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
public enum JvmMethodParameterKind {
|
public enum JvmMethodParameterKind {
|
||||||
VALUE,
|
VALUE,
|
||||||
THIS,
|
THIS,
|
||||||
@@ -24,5 +26,11 @@ public enum JvmMethodParameterKind {
|
|||||||
SHARED_VAR,
|
SHARED_VAR,
|
||||||
ENUM_NAME,
|
ENUM_NAME,
|
||||||
ENUM_ORDINAL,
|
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];
|
Class<?> inner = outer.getDeclaredClasses()[0];
|
||||||
Constructor constructor = inner.getDeclaredConstructor(outer, int.class);
|
Constructor constructor = inner.getDeclaredConstructor(outer, int.class);
|
||||||
assertNotNull(constructor);
|
assertNotNull(constructor);
|
||||||
// Get annotations for first real parameter
|
// Get annotations for first parameter
|
||||||
Annotation[] annotations = constructor.getParameterAnnotations()[1];
|
Annotation[] annotations = constructor.getParameterAnnotations()[0];
|
||||||
assertNotNull(getDeprecatedAnnotationFromList(annotations));
|
assertNotNull(getDeprecatedAnnotationFromList(annotations));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
@@ -73,6 +73,21 @@ public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAg
|
|||||||
doTest("compiler/testData/compileJavaAgainstKotlin/class/ImplementsMapPP.kt");
|
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")
|
@TestMetadata("kt3561.kt")
|
||||||
public void testKt3561() throws Exception {
|
public void testKt3561() throws Exception {
|
||||||
doTest("compiler/testData/compileJavaAgainstKotlin/class/kt3561.kt");
|
doTest("compiler/testData/compileJavaAgainstKotlin/class/kt3561.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user