From 139e376f7c665d2e50682f74405ba0fa652db5a8 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Sat, 2 Jun 2012 02:18:29 +0400 Subject: [PATCH] fix KT-2167 (enum generation) #KT-2167 fixed --- .../org/jetbrains/jet/codegen/JetTypeMapper.java | 15 +++++++++++++++ .../testData/codegen/enum/asReturnExpression.kt | 14 ++++++++++++++ .../org/jetbrains/jet/codegen/EnumGenTest.java | 5 +++++ 3 files changed, 34 insertions(+) create mode 100644 compiler/testData/codegen/enum/asReturnExpression.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java index f7511ca3529..5c3e07a8c5c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java @@ -311,6 +311,21 @@ public class JetTypeMapper { throw new IllegalStateException("missed something"); } + if (descriptor instanceof ClassDescriptor) { + ClassDescriptor klass = (ClassDescriptor) descriptor; + if (klass.getKind() == ClassKind.OBJECT) { + if (klass.getContainingDeclaration() instanceof ClassDescriptor) { + ClassDescriptor containingKlass = (ClassDescriptor) klass.getContainingDeclaration(); + if (containingKlass.getKind() == ClassKind.ENUM_CLASS) { + return getFQName(containingKlass); + } + } + } + else if (klass.getKind() == ClassKind.ENUM_ENTRY) { + return getFQName(klass.getContainingDeclaration()); + } + } + DeclarationDescriptor container = descriptor.getContainingDeclaration(); Name name = descriptor.getName(); if(JetPsiUtil.NO_NAME_PROVIDED.equals(name)) { diff --git a/compiler/testData/codegen/enum/asReturnExpression.kt b/compiler/testData/codegen/enum/asReturnExpression.kt new file mode 100644 index 00000000000..94bab54007c --- /dev/null +++ b/compiler/testData/codegen/enum/asReturnExpression.kt @@ -0,0 +1,14 @@ +// http://youtrack.jetbrains.com/issue/KT-2167 + +enum class Season { + WINTER + SPRING + SUMMER + AUTUMN +} + +fun foo() = Season.SPRING + +fun box() = + if (foo() == Season.SPRING) "OK" + else "fail" diff --git a/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java index e932423d1a0..408407f65d0 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java @@ -34,4 +34,9 @@ public class EnumGenTest extends CodegenTestCase { blackBoxFile("enum/simple.kt"); } + public void testAsReturnExpression() { + blackBoxFile("enum/asReturnExpression.kt"); + } + + }