use receiver type as owner when calling Java methods
This commit is contained in:
@@ -680,16 +680,21 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
Method methodDescriptor;
|
||||
if (declarationPsiElement instanceof PsiMethod) {
|
||||
PsiMethod psiMethod = (PsiMethod) declarationPsiElement;
|
||||
String owner = JetTypeMapper.jvmName(psiMethod.getContainingClass());
|
||||
methodDescriptor = getMethodDescriptor(psiMethod);
|
||||
final boolean isStatic = psiMethod.hasModifierProperty(PsiModifier.STATIC);
|
||||
|
||||
if (!isStatic) {
|
||||
ensureReceiverOnStack(expression);
|
||||
if (expression.getParent() instanceof JetQualifiedExpression) {
|
||||
final JetExpression receiver = ((JetQualifiedExpression) expression.getParent()).getReceiverExpression();
|
||||
owner = expressionType(receiver).getInternalName();
|
||||
}
|
||||
}
|
||||
pushMethodArguments(expression, methodDescriptor);
|
||||
|
||||
v.visitMethodInsn(isStatic ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL,
|
||||
JetTypeMapper.jvmName(psiMethod.getContainingClass()),
|
||||
owner,
|
||||
methodDescriptor.getName(),
|
||||
methodDescriptor.getDescriptor());
|
||||
}
|
||||
|
||||
@@ -393,4 +393,11 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
main.invoke(null, l);
|
||||
assertEquals(10, l.get(0).intValue());
|
||||
}
|
||||
|
||||
public void testCallMethodDeclaredInSuperclass() throws Exception {
|
||||
loadText("fun foo(sb: StringBuilder) = sb.charAt(0)");
|
||||
final Method main = generateFunction();
|
||||
final StringBuilder sb = new StringBuilder("x");
|
||||
assertEquals('x', ((Character) main.invoke(null, sb)).charValue());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user