KT-7897 Do not require to call enum constructor for each entry if all parameters have default values
Do not report an error on enum entry without initializer if all parameters have default values (error is still reported if there is no such constructor, or if the constructor call is ambiguous). Record resolved call on KtEnumEntry. NB is the enum entry has a corresponding subclass, we still have to generate the "default" constructor call, because FE doesn't know about the platform-specific representation of that class and its constructors. See also KT-14097, KT-15900
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
enum class Test(val str: String = "OK") {
|
||||
OK
|
||||
}
|
||||
|
||||
fun box(): String =
|
||||
Test.OK.str
|
||||
@@ -0,0 +1,9 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
enum class Test(vararg xs: Int) {
|
||||
OK;
|
||||
val values = xs
|
||||
}
|
||||
|
||||
fun box(): String =
|
||||
if (Test.OK.values.size == 0) "OK" else "Fail"
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
// see KT-14097
|
||||
|
||||
enum class Test(val x: Int, val str: String) {
|
||||
OK;
|
||||
constructor(x: Int = 0) : this(x, "OK")
|
||||
}
|
||||
|
||||
fun box(): String =
|
||||
Test.OK.str
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
// see KT-14097
|
||||
|
||||
enum class Test(val x: Int, val str: String) {
|
||||
OK;
|
||||
constructor(vararg xs: Int) : this(xs.size + 42, "OK")
|
||||
}
|
||||
|
||||
fun box(): String =
|
||||
if (Test.OK.x == 42)
|
||||
Test.OK.str
|
||||
else
|
||||
"Fail"
|
||||
Reference in New Issue
Block a user