toString() for FunctionN classes

It's implemented as if the types were reified: getting the real type parameters
of the corresponding FunctionN class
This commit is contained in:
Alexander Udalov
2013-03-25 21:57:41 +04:00
parent 0ec1f20140
commit 76fa9642f0
50 changed files with 228 additions and 3 deletions
@@ -308,14 +308,15 @@ public class ClosureCodegen extends GenerationStateAware {
signatureWriter.visitArrayType();
rawRetType = rawRetType.getElementType();
}
if (rawRetType.getSort() == Type.OBJECT) {
signatureWriter.visitClassType(rawRetType.getInternalName());
signatureWriter.visitEnd();
}
else {
// rawRetType is primitive
assert isPrimitive(rawRetType);
signatureWriter.visitBaseType(rawRetType.getDescriptor().charAt(0));
}
signatureWriter.visitEnd();
}
private static FunctionDescriptor getInvokeFunction(FunctionDescriptor funDescriptor) {
@@ -0,0 +1,28 @@
fun check(expected: String, obj: Any?) {
val actual = obj.toString()
if (actual != expected)
throw AssertionError("Expected: $expected, actual: $actual")
}
fun box(): String {
check("jet.FunctionImpl0<jet.Unit>")
{ () : Unit -> }
check("jet.FunctionImpl0<java.lang.Integer>")
{ () : Int -> 42 }
check("jet.FunctionImpl1<java.lang.String, java.lang.Long>")
{ (s: String) : Long -> 42.toLong() }
check("jet.FunctionImpl2<java.lang.Integer, java.lang.Integer, jet.Unit>")
{ (x: Int, y: Int) : Unit -> }
check("jet.ExtensionFunctionImpl0<java.lang.Integer, jet.Unit>")
{ Int.() : Unit -> }
check("jet.ExtensionFunctionImpl0<jet.Unit, java.lang.Integer>")
{ Unit.() : Int -> 42 }
check("jet.ExtensionFunctionImpl1<java.lang.String, java.lang.String, java.lang.Long>")
{ String.(s: String) : Long -> 42.toLong() }
check("jet.ExtensionFunctionImpl2<java.lang.Integer, java.lang.Integer, java.lang.Integer, jet.Unit>")
{ Int.(x: Int, y: Int) : Unit -> }
return "OK"
}
@@ -1764,6 +1764,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/functions/functionExpression.kt");
}
@TestMetadata("functionNtoString.kt")
public void testFunctionNtoString() throws Exception {
doTest("compiler/testData/codegen/box/functions/functionNtoString.kt");
}
@TestMetadata("invoke.kt")
public void testInvoke() throws Exception {
doTest("compiler/testData/codegen/box/functions/invoke.kt");