Skip to content

Commit

Permalink
Value classes: Support @JvmName annotation on functions with inline
Browse files Browse the repository at this point in the history
classes in signatures, but not on methods of inline classes.
  • Loading branch information
ilmirus committed Nov 27, 2020
1 parent 871912f commit 78e607c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ class JvmNameAnnotationChecker : DeclarationChecker {
if (descriptor is CallableMemberDescriptor) {
if (DescriptorUtils.isOverride(descriptor) || descriptor.isOverridable) {
diagnosticHolder.report(ErrorsJvm.INAPPLICABLE_JVM_NAME.on(annotationEntry))
} else if (descriptor.containingDeclaration.isInlineClassThatRequiresMangling() ||
requiresFunctionNameManglingForParameterTypes(descriptor) ||
requiresFunctionNameManglingForReturnType(descriptor)
) {
} else if (descriptor.containingDeclaration.isInlineClassThatRequiresMangling()) {
diagnosticHolder.report(ErrorsJvm.INAPPLICABLE_JVM_NAME.on(annotationEntry))
}
}
Expand Down
29 changes: 29 additions & 0 deletions compiler/testData/codegen/bytecodeListing/inlineClasses/jvmName.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// !LANGUAGE: +InlineClasses
// WITH_RUNTIME

inline class Foo(val a: Any)

@JvmName("bar")
fun bar(f: Foo) {}

@JvmName("baz")
fun baz(r: Result<Int>) {}

@JvmName("test")
fun returnsInlineClass() = Foo(1)

@JvmName("test")
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
fun returnsKotlinResult(a: Result<Int>): Result<Int> = a

class C {
@JvmName("test")
fun returnsInlineClass() = Foo(1)

@JvmName("test")
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
fun returnsKotlinResult(a: Result<Int>): Result<Int> = a
}

@JvmName("extensionFun")
fun Foo.extensionFun() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@kotlin.Metadata
public final class C {
// source: 'jvmName.kt'
public method <init>(): void
public final @kotlin.jvm.JvmName @org.jetbrains.annotations.NotNull method test(): java.lang.Object
public final @kotlin.jvm.JvmName @org.jetbrains.annotations.NotNull method test(@org.jetbrains.annotations.NotNull p0: java.lang.Object): java.lang.Object
}

@kotlin.Metadata
public final class Foo {
// source: 'jvmName.kt'
private final @org.jetbrains.annotations.NotNull field a: java.lang.Object
private synthetic method <init>(p0: java.lang.Object): void
public synthetic final static method box-impl(p0: java.lang.Object): Foo
public static @org.jetbrains.annotations.NotNull method constructor-impl(@org.jetbrains.annotations.NotNull p0: java.lang.Object): java.lang.Object
public method equals(p0: java.lang.Object): boolean
public static method equals-impl(p0: java.lang.Object, p1: java.lang.Object): boolean
public final static method equals-impl0(p0: java.lang.Object, p1: java.lang.Object): boolean
public final @org.jetbrains.annotations.NotNull method getA(): java.lang.Object
public method hashCode(): int
public static method hashCode-impl(p0: java.lang.Object): int
public method toString(): java.lang.String
public static method toString-impl(p0: java.lang.Object): java.lang.String
public synthetic final method unbox-impl(): java.lang.Object
}

@kotlin.Metadata
public final class JvmNameKt {
// source: 'jvmName.kt'
public final static @kotlin.jvm.JvmName method bar(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void
public final static @kotlin.jvm.JvmName method baz(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void
public final static @kotlin.jvm.JvmName method extensionFun(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void
public final static @kotlin.jvm.JvmName @org.jetbrains.annotations.NotNull method test(): java.lang.Object
public final static @kotlin.jvm.JvmName @org.jetbrains.annotations.NotNull method test(@org.jetbrains.annotations.NotNull p0: java.lang.Object): java.lang.Object
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ inline class Foo(val x: Int) {
fun simple() {}
}

<!INAPPLICABLE_JVM_NAME!>@JvmName("bad")<!>
@JvmName("bad")
fun bar(f: Foo) {}

@JvmName("good")
Expand All @@ -19,12 +19,12 @@ fun returnsInlineClass() = Foo(1)
fun returnsKotlinResult(a: Result<Int>): <!RESULT_CLASS_IN_RETURN_TYPE!>Result<Int><!> = a

class C {
<!INAPPLICABLE_JVM_NAME!>@JvmName("test")<!>
@JvmName("test")
fun returnsInlineClass() = Foo(1)

<!INAPPLICABLE_JVM_NAME!>@JvmName("test")<!>
@JvmName("test")
fun returnsKotlinResult(a: Result<Int>): <!RESULT_CLASS_IN_RETURN_TYPE!>Result<Int><!> = a
}

<!INAPPLICABLE_JVM_NAME!>@JvmName("extensionFun")<!>
@JvmName("extensionFun")
fun Foo.extensionFun() {}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 78e607c

Please sign in to comment.