Fix for KT-12106: import static of reified companion object method throws IllegalAccessError
#KT-12106 Fixed
This commit is contained in:
committed by
Mikhael Bogdanov
parent
5df52e08cc
commit
abc7d5101d
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.psi.*;
|
|||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
|
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor;
|
||||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
@@ -235,7 +236,7 @@ public class InlineCodegen extends CallGenerator {
|
|||||||
: jvmSignature.getAsmMethod();
|
: jvmSignature.getAsmMethod();
|
||||||
|
|
||||||
MethodId methodId = new MethodId(DescriptorUtils.getFqNameSafe(functionDescriptor.getContainingDeclaration()), asmMethod);
|
MethodId methodId = new MethodId(DescriptorUtils.getFqNameSafe(functionDescriptor.getContainingDeclaration()), asmMethod);
|
||||||
final CallableMemberDescriptor directMember = JvmCodegenUtil.getDirectMember(functionDescriptor);
|
final CallableMemberDescriptor directMember = getDirectMemberAndCallableFromObject(functionDescriptor);
|
||||||
if (!isBuiltInArrayIntrinsic(functionDescriptor) && !(directMember instanceof DeserializedCallableMemberDescriptor)) {
|
if (!isBuiltInArrayIntrinsic(functionDescriptor) && !(directMember instanceof DeserializedCallableMemberDescriptor)) {
|
||||||
return doCreateMethodNodeFromSource(functionDescriptor, jvmSignature, codegen, context, callDefault, state, asmMethod);
|
return doCreateMethodNodeFromSource(functionDescriptor, jvmSignature, codegen, context, callDefault, state, asmMethod);
|
||||||
}
|
}
|
||||||
@@ -256,6 +257,15 @@ public class InlineCodegen extends CallGenerator {
|
|||||||
return resultInCache.copyWithNewNode(cloneMethodNode(resultInCache.getNode()));
|
return resultInCache.copyWithNewNode(cloneMethodNode(resultInCache.getNode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static CallableMemberDescriptor getDirectMemberAndCallableFromObject(@NotNull FunctionDescriptor functionDescriptor) {
|
||||||
|
CallableMemberDescriptor directMember = JvmCodegenUtil.getDirectMember(functionDescriptor);
|
||||||
|
if (directMember instanceof ImportedFromObjectCallableDescriptor) {
|
||||||
|
return ((ImportedFromObjectCallableDescriptor) directMember).getCallableFromObject();
|
||||||
|
}
|
||||||
|
return directMember;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static MethodNode cloneMethodNode(@NotNull MethodNode methodNode) {
|
private static MethodNode cloneMethodNode(@NotNull MethodNode methodNode) {
|
||||||
methodNode.instructions.resetLabels();
|
methodNode.instructions.resetLabels();
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve
|
|||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
|
|
||||||
abstract class ImportedFromObjectCallableDescriptor<out TCallable : CallableDescriptor>(
|
abstract class ImportedFromObjectCallableDescriptor<out TCallable : CallableMemberDescriptor>(
|
||||||
val callableFromObject: TCallable
|
val callableFromObject: TCallable
|
||||||
) : CallableDescriptor {
|
) : CallableDescriptor {
|
||||||
val containingObject = callableFromObject.containingDeclaration as ClassDescriptor
|
val containingObject = callableFromObject.containingDeclaration as ClassDescriptor
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// FILE: 1.kt
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
object Host {
|
||||||
|
// private final foo()V
|
||||||
|
inline fun <reified T> foo(): String {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
|
||||||
|
import test.Host.foo
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return foo<Any>()
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// FILE: 1.kt
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
object Host {
|
||||||
|
|
||||||
|
inline val <reified T : Any> T.foo: String
|
||||||
|
get() = T::class.java.simpleName
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
|
||||||
|
import test.Host.foo
|
||||||
|
|
||||||
|
class OK
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return OK().foo
|
||||||
|
}
|
||||||
@@ -1789,12 +1789,24 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("funImportedFromObject.kt")
|
||||||
|
public void testFunImportedFromObject() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/funImportedFromObject.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("params.kt")
|
@TestMetadata("params.kt")
|
||||||
public void testParams() throws Exception {
|
public void testParams() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/params.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/params.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("propImportedFromObject.kt")
|
||||||
|
public void testPropImportedFromObject() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/propImportedFromObject.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("rootConstructor.kt")
|
@TestMetadata("rootConstructor.kt")
|
||||||
public void testRootConstructor() throws Exception {
|
public void testRootConstructor() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/rootConstructor.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/rootConstructor.kt");
|
||||||
|
|||||||
+12
@@ -1789,12 +1789,24 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("funImportedFromObject.kt")
|
||||||
|
public void testFunImportedFromObject() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/funImportedFromObject.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("params.kt")
|
@TestMetadata("params.kt")
|
||||||
public void testParams() throws Exception {
|
public void testParams() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/params.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/params.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("propImportedFromObject.kt")
|
||||||
|
public void testPropImportedFromObject() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/propImportedFromObject.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("rootConstructor.kt")
|
@TestMetadata("rootConstructor.kt")
|
||||||
public void testRootConstructor() throws Exception {
|
public void testRootConstructor() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/rootConstructor.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/rootConstructor.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user