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:
Dmitry Petrov
2017-01-20 14:47:42 +03:00
parent d13c34200b
commit ee9a174c1f
23 changed files with 539 additions and 16 deletions
+27
View File
@@ -116,3 +116,30 @@ FILE /enum.kt
SYNTHETIC_BODY kind=ENUM_VALUES
FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): TestEnum4
SYNTHETIC_BODY kind=ENUM_VALUEOF
CLASS ENUM_CLASS TestEnum5
CONSTRUCTOR private constructor TestEnum5(x: kotlin.Int = ...)
x: EXPRESSION_BODY
CONST Int type=kotlin.Int value='0'
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'constructor Enum(String, Int)'
INSTANCE_INITIALIZER_CALL classDescriptor='TestEnum5'
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: GET_VAR '<receiver: TestEnum5>' type=TestEnum5 origin=null
ENUM_ENTRY enum entry TEST1
init: ENUM_CONSTRUCTOR_CALL 'constructor TestEnum5(Int = ...)'
ENUM_ENTRY enum entry TEST2
init: ENUM_CONSTRUCTOR_CALL 'constructor TestEnum5(Int = ...)'
ENUM_ENTRY enum entry TEST3
init: ENUM_CONSTRUCTOR_CALL 'constructor TestEnum5(Int = ...)'
x: CONST Int type=kotlin.Int value='0'
FUN ENUM_CLASS_SPECIAL_MEMBER public final fun values(): kotlin.Array<TestEnum5>
SYNTHETIC_BODY kind=ENUM_VALUES
FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): TestEnum5
SYNTHETIC_BODY kind=ENUM_VALUEOF