fix PropertyGenTest: context of a function can be not only a class but also a namespace

This commit is contained in:
Dmitry Jemerov
2011-05-12 19:05:17 +02:00
parent 7c263c3e95
commit 0e864dd9dc
2 changed files with 10 additions and 6 deletions
@@ -53,7 +53,7 @@ public class ExpressionCodegen extends JetVisitor {
private final FrameMap myMap;
private final JetTypeMapper typeMapper;
private final Type returnType;
private final ClassDescriptor contextType;
private final DeclarationDescriptor contextType;
private final OwnerKind contextKind;
private final BindingContext bindingContext;
@@ -62,7 +62,7 @@ public class ExpressionCodegen extends JetVisitor {
FrameMap myMap,
JetTypeMapper typeMapper,
Type returnType,
ClassDescriptor contextType,
DeclarationDescriptor contextType,
OwnerKind contextKind) {
this.myMap = myMap;
this.typeMapper = typeMapper;
@@ -1194,11 +1194,12 @@ public class ExpressionCodegen extends JetVisitor {
throw new UnsupportedOperationException("Cannot generate this expression in top level context");
}
ClassDescriptor contextClass = (ClassDescriptor) contextType;
if (contextKind == OwnerKind.IMPLEMENTATION) {
v.load(0, JetTypeMapper.jetImplementationType(contextType));
v.load(0, JetTypeMapper.jetImplementationType(contextClass));
}
else if (contextKind == OwnerKind.DELEGATING_IMPLEMENTATION) {
v.getfield(JetTypeMapper.jvmName(contextType, contextKind), "$this", JetTypeMapper.jetInterfaceType(contextType).getDescriptor());
v.getfield(JetTypeMapper.jvmName(contextClass, contextKind), "$this", JetTypeMapper.jetInterfaceType(contextClass).getDescriptor());
}
else {
throw new UnsupportedOperationException("Unknown kind: " + contextKind);
@@ -1,6 +1,7 @@
package org.jetbrains.jet.codegen;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -46,7 +47,9 @@ public class FunctionCodegen {
boolean isAbstract = kind == OwnerKind.INTERFACE || bodyExpression == null;
if (isAbstract) flags |= Opcodes.ACC_ABSTRACT;
ClassDescriptor ownerClass = owner instanceof JetClass ? bindingContext.getClassDescriptor((JetClass) owner) : null;
DeclarationDescriptor contextDescriptor = owner instanceof JetClass
? bindingContext.getClassDescriptor((JetClass) owner)
: bindingContext.getNamespaceDescriptor((JetNamespace) owner);
final MethodVisitor mv = v.visitMethod(flags, jvmSignature.getName(), jvmSignature.getDescriptor(), null, null);
if (kind != OwnerKind.INTERFACE) {
@@ -63,7 +66,7 @@ public class FunctionCodegen {
frameMap.enter(parameter, argTypes[i].getSize());
}
ExpressionCodegen codegen = new ExpressionCodegen(mv, bindingContext, frameMap, typeMapper, jvmSignature.getReturnType(), ownerClass, kind);
ExpressionCodegen codegen = new ExpressionCodegen(mv, bindingContext, frameMap, typeMapper, jvmSignature.getReturnType(), contextDescriptor, kind);
if (kind instanceof OwnerKind.DelegateKind) {
OwnerKind.DelegateKind dk = (OwnerKind.DelegateKind) kind;
InstructionAdapter iv = new InstructionAdapter(mv);