From 4bb6c61a5a046a4d2bf86c972cd3e927783d1aa4 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 26 Feb 2018 17:49:02 +0300 Subject: [PATCH] Don't generate enum entry initializers for 'expect enum class' --- .../psi2ir/generators/ClassGenerator.kt | 8 ++- .../multiplatform/expectedEnumClass.kt | 12 ++++ .../multiplatform/expectedEnumClass.txt | 72 +++++++++++++++++++ .../multiplatform/expectedSealedClass.kt | 7 ++ .../multiplatform/expectedSealedClass.txt | 47 ++++++++++++ .../kotlin/ir/IrTextTestCaseGenerated.java | 12 ++++ 6 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.kt create mode 100644 compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.txt create mode 100644 compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.kt create mode 100644 compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.txt diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt index c2a13112be2..c0d304e39fd 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt @@ -282,9 +282,11 @@ class ClassGenerator(declarationGenerator: DeclarationGenerator) : DeclarationGe IrDeclarationOrigin.DEFINED, enumEntryDescriptor ).buildWithScope { irEnumEntry -> - irEnumEntry.initializerExpression = - createBodyGenerator(irEnumEntry.symbol) - .generateEnumEntryInitializer(ktEnumEntry, enumEntryDescriptor) + if (!enumEntryDescriptor.isExpect) { + irEnumEntry.initializerExpression = + createBodyGenerator(irEnumEntry.symbol) + .generateEnumEntryInitializer(ktEnumEntry, enumEntryDescriptor) + } if (ktEnumEntry.declarations.isNotEmpty()) { irEnumEntry.correspondingClass = generateClass(ktEnumEntry) diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.kt b/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.kt new file mode 100644 index 00000000000..d5453638655 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +MultiPlatformProjects + +expect enum class MyEnum { + FOO, + BAR +} + +actual enum class MyEnum { + FOO, + BAR, + BAZ +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.txt b/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.txt new file mode 100644 index 00000000000..7b7bd34869b --- /dev/null +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.txt @@ -0,0 +1,72 @@ +FILE fqName: fileName:/expectedEnumClass.kt + CLASS ENUM_CLASS name:MyEnum modality:FINAL visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:MyEnum flags: + ENUM_ENTRY name:FOO + ENUM_ENTRY name:BAR + FUN FAKE_OVERRIDE name:clone visibility:protected modality:FINAL <> ($this:kotlin.Enum) returnType:Any flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + FUN FAKE_OVERRIDE name:finalize visibility:protected/*protected and package*/ modality:FINAL <> ($this:kotlin.Enum) returnType:Unit flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + FUN FAKE_OVERRIDE name:getDeclaringClass visibility:public modality:FINAL <> ($this:kotlin.Enum) returnType:(java.lang.Class<(MyEnum..MyEnum?)>..java.lang.Class<(MyEnum..MyEnum?)>?) flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + FUN FAKE_OVERRIDE name:compareTo visibility:public modality:FINAL <> ($this:kotlin.Enum, other:MyEnum) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + VALUE_PARAMETER name:other index:0 type:MyEnum flags: + FUN FAKE_OVERRIDE name:equals visibility:public modality:FINAL <> ($this:kotlin.Enum, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:FINAL <> ($this:kotlin.Enum) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + PROPERTY FAKE_OVERRIDE name:name type:kotlin.String visibility:public modality:FINAL flags:val + FUN FAKE_OVERRIDE name: visibility:public modality:FINAL <> ($this:kotlin.Enum) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + PROPERTY FAKE_OVERRIDE name:ordinal type:kotlin.Int visibility:public modality:FINAL flags:val + FUN FAKE_OVERRIDE name: visibility:public modality:FINAL <> ($this:kotlin.Enum) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Enum) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + FUN ENUM_CLASS_SPECIAL_MEMBER name:values visibility:public modality:FINAL <> () returnType:Array flags: + SYNTHETIC_BODY kind=ENUM_VALUES + FUN ENUM_CLASS_SPECIAL_MEMBER name:valueOf visibility:public modality:FINAL <> (value:kotlin.String) returnType:MyEnum flags: + VALUE_PARAMETER name:value index:0 type:kotlin.String flags: + SYNTHETIC_BODY kind=ENUM_VALUEOF + CLASS ENUM_CLASS name:MyEnum modality:FINAL visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:MyEnum flags: + CONSTRUCTOR visibility:private <> () returnType:MyEnum flags: + BLOCK_BODY + ENUM_CONSTRUCTOR_CALL 'constructor Enum(String, Int)' + >: null + INSTANCE_INITIALIZER_CALL classDescriptor='MyEnum' + ENUM_ENTRY name:FOO + init: ENUM_CONSTRUCTOR_CALL 'constructor MyEnum()' + ENUM_ENTRY name:BAR + init: ENUM_CONSTRUCTOR_CALL 'constructor MyEnum()' + ENUM_ENTRY name:BAZ + init: ENUM_CONSTRUCTOR_CALL 'constructor MyEnum()' + FUN FAKE_OVERRIDE name:clone visibility:protected modality:FINAL <> ($this:kotlin.Enum) returnType:Any flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + FUN FAKE_OVERRIDE name:finalize visibility:protected/*protected and package*/ modality:FINAL <> ($this:kotlin.Enum) returnType:Unit flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + FUN FAKE_OVERRIDE name:getDeclaringClass visibility:public modality:FINAL <> ($this:kotlin.Enum) returnType:(java.lang.Class<(MyEnum..MyEnum?)>..java.lang.Class<(MyEnum..MyEnum?)>?) flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + FUN FAKE_OVERRIDE name:compareTo visibility:public modality:FINAL <> ($this:kotlin.Enum, other:MyEnum) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + VALUE_PARAMETER name:other index:0 type:MyEnum flags: + FUN FAKE_OVERRIDE name:equals visibility:public modality:FINAL <> ($this:kotlin.Enum, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:FINAL <> ($this:kotlin.Enum) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + PROPERTY FAKE_OVERRIDE name:name type:kotlin.String visibility:public modality:FINAL flags:val + FUN FAKE_OVERRIDE name: visibility:public modality:FINAL <> ($this:kotlin.Enum) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + PROPERTY FAKE_OVERRIDE name:ordinal type:kotlin.Int visibility:public modality:FINAL flags:val + FUN FAKE_OVERRIDE name: visibility:public modality:FINAL <> ($this:kotlin.Enum) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Enum) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Enum flags: + FUN ENUM_CLASS_SPECIAL_MEMBER name:values visibility:public modality:FINAL <> () returnType:Array flags: + SYNTHETIC_BODY kind=ENUM_VALUES + FUN ENUM_CLASS_SPECIAL_MEMBER name:valueOf visibility:public modality:FINAL <> (value:kotlin.String) returnType:MyEnum flags: + VALUE_PARAMETER name:value index:0 type:kotlin.String flags: + SYNTHETIC_BODY kind=ENUM_VALUEOF diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.kt b/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.kt new file mode 100644 index 00000000000..1f78dab971e --- /dev/null +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: +MultiPlatformProjects + +expect sealed class Ops() +expect class Add() : Ops + +actual sealed class Ops actual constructor() +actual class Add actual constructor() : Ops() \ No newline at end of file diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.txt b/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.txt new file mode 100644 index 00000000000..fcbe225bc1c --- /dev/null +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.txt @@ -0,0 +1,47 @@ +FILE fqName: fileName:/expectedSealedClass.kt + CLASS CLASS name:Ops modality:SEALED visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Ops flags: + CONSTRUCTOR visibility:private <> () returnType:Ops flags: + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + CLASS CLASS name:Add modality:FINAL visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Add flags: + CONSTRUCTOR visibility:public <> () returnType:Add flags: + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + CLASS CLASS name:Ops modality:SEALED visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Ops flags: + CONSTRUCTOR visibility:private <> () returnType:Ops flags: + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + INSTANCE_INITIALIZER_CALL classDescriptor='Ops' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + CLASS CLASS name:Add modality:FINAL visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Add flags: + CONSTRUCTOR visibility:public <> () returnType:Add flags: + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor Ops()' + INSTANCE_INITIALIZER_CALL classDescriptor='Add' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 41348e02e71..a3ed0e77471 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -331,6 +331,18 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.kt"); doTest(fileName); } + + @TestMetadata("expectedEnumClass.kt") + public void testExpectedEnumClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.kt"); + doTest(fileName); + } + + @TestMetadata("expectedSealedClass.kt") + public void testExpectedSealedClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/ir/irText/declarations/parameters")