KT-3308: Support local generic functions in codegen
#KT-3308 Fixed
This commit is contained in:
@@ -1624,6 +1624,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
// descriptor = ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
|
// descriptor = ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
assert descriptor != null : "Couldn't find descriptor for '" + expression.getText() + "'";
|
||||||
|
descriptor = descriptor.getOriginal();
|
||||||
|
|
||||||
if (descriptor instanceof CallableMemberDescriptor) {
|
if (descriptor instanceof CallableMemberDescriptor) {
|
||||||
CallableMemberDescriptor memberDescriptor = (CallableMemberDescriptor) descriptor;
|
CallableMemberDescriptor memberDescriptor = (CallableMemberDescriptor) descriptor;
|
||||||
memberDescriptor = unwrapFakeOverride(memberDescriptor);
|
memberDescriptor = unwrapFakeOverride(memberDescriptor);
|
||||||
@@ -1635,9 +1638,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
assert descriptor != null;
|
|
||||||
|
|
||||||
if (descriptor instanceof VariableDescriptorForObject) {
|
if (descriptor instanceof VariableDescriptorForObject) {
|
||||||
VariableDescriptorForObject variableDescriptor = (VariableDescriptorForObject) descriptor;
|
VariableDescriptorForObject variableDescriptor = (VariableDescriptorForObject) descriptor;
|
||||||
ClassDescriptor objectClassDescriptor = variableDescriptor.getObjectClass();
|
ClassDescriptor objectClassDescriptor = variableDescriptor.getObjectClass();
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
fun box() : String {
|
||||||
|
|
||||||
|
fun <T> local(s : T) : T {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(s : Int) : Int {
|
||||||
|
return local(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test(10) != 10) return "fail1"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box() : String {
|
||||||
|
fun foo<T>(t:() -> T) : T = t()
|
||||||
|
|
||||||
|
return foo {}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fun box() : String {
|
||||||
|
|
||||||
|
fun <T> local(s : T) : T {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (local(10) != 10) return "fail1"
|
||||||
|
|
||||||
|
if (local("11") != "11") return "fail2"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -1139,6 +1139,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box/closures"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box/closures"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("capturedLocalGenericFun.kt")
|
||||||
|
public void testCapturedLocalGenericFun() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/box/closures/capturedLocalGenericFun.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("closureInsideConstrucor.kt")
|
@TestMetadata("closureInsideConstrucor.kt")
|
||||||
public void testClosureInsideConstrucor() throws Exception {
|
public void testClosureInsideConstrucor() throws Exception {
|
||||||
doTest("compiler/testData/codegen/box/closures/closureInsideConstrucor.kt");
|
doTest("compiler/testData/codegen/box/closures/closureInsideConstrucor.kt");
|
||||||
@@ -1189,6 +1194,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
doTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt3905.kt")
|
||||||
|
public void testKt3905() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/box/closures/kt3905.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("localFunctionInFunction.kt")
|
@TestMetadata("localFunctionInFunction.kt")
|
||||||
public void testLocalFunctionInFunction() throws Exception {
|
public void testLocalFunctionInFunction() throws Exception {
|
||||||
doTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt");
|
doTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt");
|
||||||
@@ -1199,6 +1209,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest("compiler/testData/codegen/box/closures/localFunctionInInitializer.kt");
|
doTest("compiler/testData/codegen/box/closures/localFunctionInInitializer.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("localGenericFun.kt")
|
||||||
|
public void testLocalGenericFun() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/box/closures/localGenericFun.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("localReturn.kt")
|
@TestMetadata("localReturn.kt")
|
||||||
public void testLocalReturn() throws Exception {
|
public void testLocalReturn() throws Exception {
|
||||||
doTest("compiler/testData/codegen/box/closures/localReturn.kt");
|
doTest("compiler/testData/codegen/box/closures/localReturn.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user