From 0e864dd9dcfbf30b9d839b81ed967712293ab9bf Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 12 May 2011 19:05:17 +0200 Subject: [PATCH] fix PropertyGenTest: context of a function can be not only a class but also a namespace --- .../src/org/jetbrains/jet/codegen/ExpressionCodegen.java | 9 +++++---- idea/src/org/jetbrains/jet/codegen/FunctionCodegen.java | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 659052dcfd2..9a0aa01acdc 100644 --- a/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -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); diff --git a/idea/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/idea/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 74eba882f04..e45f4a34e6d 100644 --- a/idea/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/idea/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -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);