Refine multi-file facades generation
Do not generate delegation from multi-file facade to inline-only functions because they are effectively private in bytecode #KT-10858 Fixed
This commit is contained in:
@@ -213,7 +213,8 @@ class MultifileClassCodegen(
|
|||||||
if (declaration is KtNamedFunction || declaration is KtProperty) {
|
if (declaration is KtNamedFunction || declaration is KtProperty) {
|
||||||
val descriptor = state.bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
|
val descriptor = state.bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
|
||||||
assert(descriptor is CallableMemberDescriptor) { "Expected callable member, was " + descriptor + " for " + declaration.text }
|
assert(descriptor is CallableMemberDescriptor) { "Expected callable member, was " + descriptor + " for " + declaration.text }
|
||||||
if (!Visibilities.isPrivate((descriptor as CallableMemberDescriptor).visibility)) {
|
if (!Visibilities.isPrivate((descriptor as CallableMemberDescriptor).visibility)
|
||||||
|
&& AsmUtil.getVisibilityAccessFlag(descriptor) != Opcodes.ACC_PRIVATE) {
|
||||||
generateCallableMemberTasks.put(descriptor, { memberCodegen.genFunctionOrProperty(declaration) })
|
generateCallableMemberTasks.put(descriptor, { memberCodegen.genFunctionOrProperty(declaration) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -1,3 +1,7 @@
|
|||||||
import a.foo
|
import a.foo
|
||||||
|
import a.inlineOnly
|
||||||
|
|
||||||
fun box(): String = foo { "OK" }
|
fun box(): String {
|
||||||
|
if (!a.inlineOnly<String>("OK")) return "fail 1"
|
||||||
|
return foo { "OK" }
|
||||||
|
}
|
||||||
|
|||||||
+2
@@ -4,3 +4,5 @@ package a
|
|||||||
inline fun foo(body: () -> String): String = bar(body())
|
inline fun foo(body: () -> String): String = bar(body())
|
||||||
|
|
||||||
public fun bar(x: String): String = x
|
public fun bar(x: String): String = x
|
||||||
|
|
||||||
|
inline fun <reified T> inlineOnly(x: Any?): Boolean = x is T
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@file:[JvmName("Foo") JvmMultifileClass]
|
||||||
|
package test
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
inlineOnly<String>()
|
||||||
|
}
|
||||||
|
|
||||||
|
// No method should be generated in multifile facade for 'inlineOnly'
|
||||||
|
// Because 'inlineOnly' is private in file part (because it's inline-only) and can't be delegated from facade
|
||||||
|
public inline fun <reified T> inlineOnly() {}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
@kotlin.Metadata
|
||||||
|
@kotlin.jvm.internal.KotlinMultifileClass
|
||||||
|
public final class test/Foo {
|
||||||
|
public final static method foo(): void
|
||||||
|
}
|
||||||
|
|
||||||
|
@kotlin.Metadata
|
||||||
|
@kotlin.jvm.internal.KotlinMultifileClassPart
|
||||||
|
synthetic final class test/Foo__InlineOnlyMultifileKt {
|
||||||
|
public final static method foo(): void
|
||||||
|
private final static method inlineOnly(): void
|
||||||
|
}
|
||||||
@@ -47,6 +47,12 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("InlineOnlyMultifile.kt")
|
||||||
|
public void testInlineOnlyMultifile() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/InlineOnlyMultifile.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/bytecodeListing/annotations")
|
@TestMetadata("compiler/testData/codegen/bytecodeListing/annotations")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user