Don't generate type annotations on synthetic accessors
#KT-35843 Fixed
This commit is contained in:
@@ -139,7 +139,7 @@ public abstract class AnnotationCodegen {
|
||||
}
|
||||
|
||||
generateAdditionalAnnotations(annotated, returnType, annotationDescriptorsAlreadyPresent);
|
||||
generateTypeAnnotations(typeForTypeAnnotations);
|
||||
generateTypeAnnotations(annotated, typeForTypeAnnotations);
|
||||
}
|
||||
|
||||
private void generateAdditionalAnnotations(
|
||||
@@ -192,15 +192,17 @@ public abstract class AnnotationCodegen {
|
||||
}
|
||||
|
||||
private static boolean isInvisibleFromTheOutside(@Nullable DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof CallableMemberDescriptor && KotlinTypeMapper.isAccessor((CallableMemberDescriptor) descriptor)) {
|
||||
return true;
|
||||
}
|
||||
if (isAccessor(descriptor)) return true;
|
||||
if (descriptor instanceof MemberDescriptor) {
|
||||
return AsmUtil.getVisibilityAccessFlag((MemberDescriptor) descriptor) == Opcodes.ACC_PRIVATE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isAccessor(@Nullable Annotated descriptor) {
|
||||
return descriptor instanceof CallableMemberDescriptor && KotlinTypeMapper.isAccessor((CallableMemberDescriptor) descriptor);
|
||||
}
|
||||
|
||||
private void generateNullabilityAnnotation(@Nullable KotlinType type, @NotNull Set<String> annotationDescriptorsAlreadyPresent) {
|
||||
if (type == null) return;
|
||||
|
||||
@@ -665,8 +667,9 @@ public abstract class AnnotationCodegen {
|
||||
return av == null ? NO_ANNOTATION_VISITOR : av;
|
||||
}
|
||||
|
||||
private void generateTypeAnnotations(@Nullable KotlinType type) {
|
||||
if (type == null ||
|
||||
private void generateTypeAnnotations(@NotNull Annotated annotated, @Nullable KotlinType type) {
|
||||
if (isAccessor(annotated) ||
|
||||
type == null ||
|
||||
state.getTarget() == JvmTarget.JVM_1_6 ||
|
||||
!state.getConfiguration().getBoolean(JVMConfigurationKeys.EMIT_JVM_TYPE_ANNOTATIONS)) {
|
||||
return;
|
||||
|
||||
@@ -58,8 +58,6 @@ public final class foo/Kotlin : java/lang/Object {
|
||||
public void <init>()
|
||||
|
||||
public final static java.lang.String access$getCompanionVarProperty$cp()
|
||||
@Lfoo/TypeAnn;([name="1"]) : METHOD_RETURN, null
|
||||
@Lfoo/TypeAnnBinary;([]) : METHOD_RETURN, null // invisible
|
||||
|
||||
public final static java.lang.String access$getJvmStatic$cp()
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ annotation class TypeAnnSource
|
||||
|
||||
class Kotlin {
|
||||
|
||||
private fun foo(s: @TypeAnn("1") @TypeAnnBinary @TypeAnnSource String) {
|
||||
fun foo(s: @TypeAnn("1") @TypeAnnBinary @TypeAnnSource String) {
|
||||
}
|
||||
|
||||
fun foo2(): @TypeAnn("2") @TypeAnnBinary @TypeAnnSource String {
|
||||
@@ -29,10 +29,6 @@ class Kotlin {
|
||||
}
|
||||
|
||||
fun fooArray2(): Array<@TypeAnn("4") @TypeAnnBinary @TypeAnnSource String>? {
|
||||
{
|
||||
foo2()
|
||||
foo("123")
|
||||
}()
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
final class foo/Kotlin$fooArray2$1 : kotlin/jvm/internal/Lambda, kotlin/jvm/functions/Function0 {
|
||||
final foo.Kotlin this$0
|
||||
|
||||
void <init>(foo.Kotlin p0)
|
||||
|
||||
public java.lang.Object invoke()
|
||||
|
||||
public final void invoke()
|
||||
}
|
||||
|
||||
public final class foo/Kotlin : java/lang/Object {
|
||||
public void <init>()
|
||||
|
||||
public final static void access$foo(foo.Kotlin $this, java.lang.String s)
|
||||
|
||||
private final void foo(java.lang.String s)
|
||||
public final void foo(java.lang.String s)
|
||||
@Lfoo/TypeAnn;([name="1"]) : METHOD_FORMAL_PARAMETER 0, null
|
||||
@Lfoo/TypeAnnBinary;([]) : METHOD_FORMAL_PARAMETER 0, null // invisible
|
||||
|
||||
@@ -40,4 +28,4 @@ public abstract interface foo/TypeAnnBinary : java/lang/Object, java/lang/annota
|
||||
|
||||
public abstract interface foo/TypeAnnSource : java/lang/Object, java/lang/annotation/Annotation {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// KOTLIN_CONFIGURATION_FLAGS: +JVM.EMIT_JVM_TYPE_ANNOTATIONS
|
||||
// TYPE_ANNOTATIONS
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
package foo
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class TypeAnn(val name: String)
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class TypeAnnBinary
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class TypeAnnSource
|
||||
|
||||
class Kotlin {
|
||||
|
||||
private fun foo(s: @TypeAnn("1") @TypeAnnBinary @TypeAnnSource String): @TypeAnn("2") @TypeAnnBinary @TypeAnnSource String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
inner class A {
|
||||
|
||||
fun fooArray2() {
|
||||
foo("123")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
public final class foo/Kotlin$A : java/lang/Object {
|
||||
final foo.Kotlin this$0
|
||||
|
||||
public void <init>(foo.Kotlin $outer)
|
||||
|
||||
public final void fooArray2()
|
||||
}
|
||||
|
||||
public final class foo/Kotlin : java/lang/Object {
|
||||
public void <init>()
|
||||
|
||||
public final static java.lang.String access$foo(foo.Kotlin $this, java.lang.String s)
|
||||
|
||||
private final java.lang.String foo(java.lang.String s)
|
||||
@Lfoo/TypeAnn;([name="2"]) : METHOD_RETURN, null
|
||||
@Lfoo/TypeAnn;([name="1"]) : METHOD_FORMAL_PARAMETER 0, null
|
||||
@Lfoo/TypeAnnBinary;([]) : METHOD_RETURN, null // invisible
|
||||
@Lfoo/TypeAnnBinary;([]) : METHOD_FORMAL_PARAMETER 0, null // invisible
|
||||
}
|
||||
|
||||
public abstract interface foo/TypeAnn : java/lang/Object, java/lang/annotation/Annotation {
|
||||
public abstract java.lang.String name()
|
||||
}
|
||||
|
||||
public abstract interface foo/TypeAnnBinary : java/lang/Object, java/lang/annotation/Annotation {
|
||||
|
||||
}
|
||||
|
||||
public abstract interface foo/TypeAnnSource : java/lang/Object, java/lang/annotation/Annotation {
|
||||
|
||||
}
|
||||
+5
@@ -193,5 +193,10 @@ public class AsmLikeInstructionListingTestGenerated extends AbstractAsmLikeInstr
|
||||
public void testStaticNested() throws Exception {
|
||||
runTest("compiler/testData/codegen/asmLike/typeAnnotations/staticNested.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticAccessors.kt")
|
||||
public void testSyntheticAccessors() throws Exception {
|
||||
runTest("compiler/testData/codegen/asmLike/typeAnnotations/syntheticAccessors.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user