diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java index 5dfd501ff89..9e1d91500ec 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java @@ -42,8 +42,9 @@ public class ClosureAnnotator { private final Map anonymousSubclassesCount = new HashMap(); private final Map classNameForScript = new HashMap(); private final Set scriptClassNames = new HashSet(); - private final Map classesForFunctions = new HashMap(); - private final Map enclosing = new HashMap(); + private final Map classesForFunctions = + new HashMap(); + private final Map enclosing = new HashMap(); private final MultiMap namespaceName2MultiNamespaceFiles = MultiMap.create(); private final MultiMap namespaceName2Files = MultiMap.create(); @@ -81,7 +82,10 @@ public class ClosureAnnotator { classDescriptor.initialize( false, Collections.emptyList(), - Collections.singleton((funDescriptor.getReceiverParameter().exists() ? JetStandardClasses.getReceiverFunction(arity) : JetStandardClasses.getFunction(arity)).getDefaultType()), JetScope.EMPTY, Collections.emptySet(), null); + Collections.singleton((funDescriptor.getReceiverParameter().exists() + ? JetStandardClasses.getReceiverFunction(arity) + : JetStandardClasses.getFunction(arity)).getDefaultType()), JetScope.EMPTY, + Collections.emptySet(), null); classesForFunctions.put(funDescriptor, classDescriptor); } return classDescriptor; @@ -169,7 +173,7 @@ public class ClosureAnnotator { ArrayList namespaceFiles = new ArrayList(); for (JetFile jetFile : entry.getValue()) { - ArrayList fileFunctions = new ArrayList(); + Collection fileFunctions = new ArrayList(); for (JetDeclaration declaration : jetFile.getDeclarations()) { if (declaration instanceof JetNamedFunction) { fileFunctions.add(declaration); @@ -181,7 +185,7 @@ public class ClosureAnnotator { } } - if(namespaceFiles.size() > 1) { + if (namespaceFiles.size() > 1) { for (JetFile namespaceFile : namespaceFiles) { namespaceName2MultiNamespaceFiles.putValue(entry.getKey(), namespaceFile); } @@ -214,7 +218,12 @@ public class ClosureAnnotator { } public boolean hasThis0(ClassDescriptor classDescriptor) { - if (DescriptorUtils.isClassObject(classDescriptor)) { return false; } + if (DescriptorUtils.isClassObject(classDescriptor)) { + return false; + } + if (classDescriptor.getKind() == ClassKind.ENUM_CLASS || classDescriptor.getKind() == ClassKind.ENUM_ENTRY) { + return false; + } ClassDescriptor other = enclosing.get(classDescriptor); return other != null; @@ -266,6 +275,7 @@ public class ClosureAnnotator { @Override public void visitJetFile(JetFile file) { if (file.isScript()) { + //noinspection ConstantConditions nameStack.push(classNameForScriptPsi(file.getScript()).getInternalName()); } else { @@ -279,6 +289,7 @@ public class ClosureAnnotator { public void visitClassObject(JetClassObject classObject) { JvmClassName name = recordClassObject(classObject); ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, classObject.getObjectDeclaration()); + assert classDescriptor != null; recordEnclosing(classDescriptor); recordName(classDescriptor, name); classStack.push(classDescriptor); @@ -303,7 +314,9 @@ public class ClosureAnnotator { if (classDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor) { nameStack.push(base.isEmpty() ? classDescriptor.getName().getName() : base + '/' + classDescriptor.getName()); } - else { nameStack.push(base + '$' + classDescriptor.getName()); } + else { + nameStack.push(base + '$' + classDescriptor.getName()); + } super.visitObjectDeclaration(declaration); nameStack.pop(); classStack.pop(); @@ -321,7 +334,9 @@ public class ClosureAnnotator { if (classDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor) { nameStack.push(base.isEmpty() ? classDescriptor.getName().getName() : base + '/' + classDescriptor.getName()); } - else { nameStack.push(base + '$' + classDescriptor.getName()); } + else { + nameStack.push(base + '$' + classDescriptor.getName()); + } super.visitClass(klass); nameStack.pop(); classStack.pop(); @@ -347,7 +362,8 @@ public class ClosureAnnotator { @Override public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { JvmClassName name = recordAnonymousClass(expression.getFunctionLiteral()); - FunctionDescriptor declarationDescriptor = (FunctionDescriptor) bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expression); + FunctionDescriptor declarationDescriptor = + (FunctionDescriptor) bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expression); // working around a problem with shallow analysis if (declarationDescriptor == null) return; ClassDescriptor classDescriptor = classDescriptorForFunctionDescriptor(declarationDescriptor, name); @@ -368,7 +384,8 @@ public class ClosureAnnotator { @Override public void visitNamedFunction(JetNamedFunction function) { - FunctionDescriptor functionDescriptor = (FunctionDescriptor) bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, function); + FunctionDescriptor functionDescriptor = + (FunctionDescriptor) bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, function); // working around a problem with shallow analysis if (functionDescriptor == null) return; DeclarationDescriptor containingDeclaration = functionDescriptor.getContainingDeclaration(); @@ -379,7 +396,9 @@ public class ClosureAnnotator { } else if (containingDeclaration instanceof NamespaceDescriptor) { String peek = nameStack.peek(); - if (peek.isEmpty()) { peek = "namespace"; } + if (peek.isEmpty()) { + peek = "namespace"; + } else { peek += "/namespace"; } diff --git a/compiler/testData/codegen/enum/inclassobj.kt b/compiler/testData/codegen/enum/inclassobj.kt new file mode 100644 index 00000000000..93a51f89657 --- /dev/null +++ b/compiler/testData/codegen/enum/inclassobj.kt @@ -0,0 +1,15 @@ +fun box() = if(Context.operatingSystemType == Context.OsType.OTHER) "OK" else "fail" + +public class Context +{ + class object + { + public enum class OsType { + LINUX; + OTHER + } + + public val operatingSystemType: OsType + get() = OsType.OTHER + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java index 5f973068657..be46d8de8cd 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java @@ -96,4 +96,8 @@ public class EnumGenTest extends CodegenTestCase { public void testValues() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { blackBoxFile("enum/valueof.kt"); } + + public void testInClassObj() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { + blackBoxFile("enum/inclassobj.kt"); + } }