Generate bridges for super-calls only when needed

#KT-2887 Fixed
This commit is contained in:
Alexander Udalov
2012-11-07 16:29:30 +04:00
parent 89b8bbec57
commit 415b6f8efe
4 changed files with 40 additions and 8 deletions
@@ -1747,8 +1747,13 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
boolean superCall = isSuperCall(call);
if (superCall && !isInterface(fd.getContainingDeclaration())) {
CodegenContext c = getParentContextSubclassOf((ClassDescriptor) fd.getContainingDeclaration());
fd = (FunctionDescriptor) c.getAccessor(unwrapFakeOverride(fd));
JetSuperExpression expression = getSuperCallExpression(call);
ClassDescriptor owner = getSuperCallLabelTarget(expression);
CodegenContext c = context.findParentContextWithDescriptor(owner);
assert c != null : "Couldn't find a context for a super-call: " + fd;
if (c != context.getParentContext()) {
fd = (FunctionDescriptor) c.getAccessor(unwrapFakeOverride(fd));
}
}
fd = accessableFunctionDescriptor(fd);
@@ -217,6 +217,16 @@ public abstract class CodegenContext {
return cur == null ? null : (ClassDescriptor) cur.getContextDescriptor();
}
@Nullable
public CodegenContext findParentContextWithDescriptor(DeclarationDescriptor descriptor) {
CodegenContext c = this;
while (c != null) {
if (c.getContextDescriptor() == descriptor) break;
c = c.getParentContext();
}
return c;
}
public DeclarationDescriptor getAccessor(DeclarationDescriptor descriptor) {
if (accessors == null) {
accessors = new HashMap<DeclarationDescriptor, DeclarationDescriptor>();