Some enum-related fixes

(NB: testEnumClass3 doesn't work yet, effective modality required for enum class)
This commit is contained in:
Dmitry Petrov
2016-09-28 17:34:44 +03:00
parent de2bef910b
commit 608d6a37d2
12 changed files with 176 additions and 41 deletions
+15 -2
View File
@@ -1,3 +1,16 @@
enum class Test { OK }
fun <T> assertEquals(actual: T, expected: T) {
if (actual != expected) {
throw java.lang.AssertionError("Assertion failed: $actual != $expected")
}
}
fun box() = Test.OK.toString()
enum class Test {
OK
}
fun box(): String {
assertEquals(Test.OK.ordinal, 0)
assertEquals(Test.OK.name, "OK")
return "OK"
}
+21
View File
@@ -0,0 +1,21 @@
fun <T> assertEquals(actual: T, expected: T) {
if (actual != expected) {
throw java.lang.AssertionError("Assertion failed: $actual != $expected")
}
}
enum class TestEnumClass(val x: Int) {
ZERO
// {
// init {
// }
// }
;
constructor(): this(0)
}
fun box(): String {
assertEquals(TestEnumClass.ZERO.x, 0)
return "OK"
}
+17
View File
@@ -0,0 +1,17 @@
fun <T> assertEquals(actual: T, expected: T) {
if (actual != expected) {
throw java.lang.AssertionError("Assertion failed: $actual != $expected")
}
}
enum class TestEnumClass {
ZERO {
override fun describe() = "nothing"
};
abstract fun describe(): String
}
fun box(): String {
assertEquals(TestEnumClass.ZERO.describe(), "nothing")
return "OK"
}
@@ -1,5 +1,10 @@
// WITH_RUNTIME
enum class Test0(val x: Int) {
ZERO;
constructor() : this(0)
}
enum class Test1(val x: Int) {
ZERO, ONE(1);
constructor() : this(0)
@@ -1,4 +1,28 @@
FILE /enumWithSecondaryCtor.kt
CLASS ENUM_CLASS Test0
CONSTRUCTOR private constructor Test0(x: kotlin.Int)
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'constructor Enum(String, Int)'
INSTANCE_INITIALIZER_CALL classDescriptor='Test0'
PROPERTY public final val x: kotlin.Int
FIELD PROPERTY_BACKING_FIELD public final val x: kotlin.Int
EXPRESSION_BODY
GET_VAR 'value-parameter x: Int' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR public final fun <get-x>(): kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-x>(): Int'
GET_FIELD 'x: Int' type=kotlin.Int origin=null
receiver: THIS of 'Test0' type=Test0
ENUM_ENTRY enum entry ZERO
init: ENUM_CONSTRUCTOR_CALL 'constructor Test0()'
CONSTRUCTOR private constructor Test0()
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'constructor Test0(Int)'
x: CONST Int type=kotlin.Int value='0'
FUN ENUM_CLASS_SPECIAL_MEMBER public final fun values(): kotlin.Array<Test0>
SYNTHETIC_BODY kind=ENUM_VALUES
FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): Test0
SYNTHETIC_BODY kind=ENUM_VALUEOF
CLASS ENUM_CLASS Test1
CONSTRUCTOR private constructor Test1(x: kotlin.Int)
BLOCK_BODY
@@ -14,7 +38,7 @@ FILE /enumWithSecondaryCtor.kt
GET_FIELD 'x: Int' type=kotlin.Int origin=null
receiver: THIS of 'Test1' type=Test1
ENUM_ENTRY enum entry ZERO
init: ENUM_CONSTRUCTOR_CALL 'constructor Test1(Int)'
init: ENUM_CONSTRUCTOR_CALL 'constructor Test1()'
ENUM_ENTRY enum entry ONE
init: ENUM_CONSTRUCTOR_CALL 'constructor Test1(Int)'
x: CONST Int type=kotlin.Int value='1'
@@ -45,7 +69,7 @@ FILE /enumWithSecondaryCtor.kt
class: CLASS ENUM_ENTRY ZERO
CONSTRUCTOR private constructor ZERO()
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'constructor Test2(Int)'
ENUM_CONSTRUCTOR_CALL 'constructor Test2()'
INSTANCE_INITIALIZER_CALL classDescriptor='ZERO'
FUN public open override fun foo(): kotlin.Unit
BLOCK_BODY