Generate lambdas in enum entry super calls

#KT-4423 Fixed
This commit is contained in:
Alexander Udalov
2014-10-16 20:19:07 +04:00
parent 1edaf43051
commit 6ec71b3fd1
3 changed files with 31 additions and 1 deletions
@@ -180,7 +180,12 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
assert descriptor != null :
String.format("No descriptor for enum entry \n---\n%s\n---\n", JetPsiUtil.getElementTextWithContext(enumEntry));
if (!enumEntry.getDeclarations().isEmpty()) {
if (enumEntry.getDeclarations().isEmpty()) {
for (JetDelegationSpecifier specifier : enumEntry.getDelegationSpecifiers()) {
specifier.accept(this);
}
}
else {
bindingTrace.record(ENUM_ENTRY_CLASS_NEED_SUBCLASS, descriptor);
super.visitEnumEntry(enumEntry);
}
@@ -0,0 +1,19 @@
// KT-4423 Enum with function not compiled
enum class Sign(val str: String, val func: (x: Int, y: Int) -> Int){
plus: Sign("+", { x, y -> x + y })
mult: Sign("*", { x, y -> x * y }) {
override fun toString() = "${func(4,5)}"
}
}
fun box(): String {
val sum = Sign.plus.func(2, 3)
if (sum != 5) return "Fail 1: $sum"
val product = Sign.mult.toString()
if (product != "20") return "Fail 2: $product"
return "OK"
}
@@ -2649,6 +2649,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("enumWithLambdaParameter.kt")
public void testEnumWithLambdaParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/enumWithLambdaParameter.kt");
doTest(fileName);
}
@TestMetadata("inPackage.kt")
public void testInPackage() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/inPackage.kt");