Generate proper generic signature for closure classes

This commit is contained in:
Alexander Udalov
2013-04-22 15:51:15 +04:00
parent ace7bd9bc8
commit 56f8f021f9
7 changed files with 120 additions and 58 deletions
@@ -0,0 +1,21 @@
fun foo(s: String) {}
class A {
fun bar(): String = ""
}
fun A.baz() {}
fun box(): String {
val f = "${::foo}"
if (f != "jet.KFunctionImpl1<? super java.lang.String, ? extends jet.Unit>") return "Fail foo: $f"
val g = "${A::bar}"
if (g != "jet.KMemberFunctionImpl0<? super A, ? extends java.lang.String>") return "Fail bar: $f"
val h = "${A::baz}"
if (h != "jet.KExtensionFunctionImpl0<? super A, ? extends jet.Unit>") return "Fail baz: $h"
return "OK"
}
@@ -6,22 +6,22 @@ fun check(expected: String, obj: Any?) {
fun box(): String {
check("jet.FunctionImpl0<jet.Unit>")
check("jet.FunctionImpl0<? extends jet.Unit>")
{ () : Unit -> }
check("jet.FunctionImpl0<java.lang.Integer>")
check("jet.FunctionImpl0<? extends java.lang.Integer>")
{ () : Int -> 42 }
check("jet.FunctionImpl1<java.lang.String, java.lang.Long>")
check("jet.FunctionImpl1<? super java.lang.String, ? extends java.lang.Long>")
{ (s: String) : Long -> 42.toLong() }
check("jet.FunctionImpl2<java.lang.Integer, java.lang.Integer, jet.Unit>")
check("jet.FunctionImpl2<? super java.lang.Integer, ? super java.lang.Integer, ? extends jet.Unit>")
{ (x: Int, y: Int) : Unit -> }
check("jet.ExtensionFunctionImpl0<java.lang.Integer, jet.Unit>")
check("jet.ExtensionFunctionImpl0<? super java.lang.Integer, ? extends jet.Unit>")
{ Int.() : Unit -> }
check("jet.ExtensionFunctionImpl0<jet.Unit, java.lang.Integer>")
check("jet.ExtensionFunctionImpl0<? super jet.Unit, ? extends java.lang.Integer>")
{ Unit.() : Int -> 42 }
check("jet.ExtensionFunctionImpl1<java.lang.String, java.lang.String, java.lang.Long>")
check("jet.ExtensionFunctionImpl1<? super java.lang.String, ? super java.lang.String, ? extends java.lang.Long>")
{ String.(s: String) : Long -> 42.toLong() }
check("jet.ExtensionFunctionImpl2<java.lang.Integer, java.lang.Integer, java.lang.Integer, jet.Unit>")
check("jet.ExtensionFunctionImpl2<? super java.lang.Integer, ? super java.lang.Integer, ? super java.lang.Integer, ? extends jet.Unit>")
{ Int.(x: Int, y: Int) : Unit -> }
return "OK"
@@ -12,18 +12,20 @@ val unitFun = { }
val intFun = { 42 }
val stringParamFun = { (x: String) : Unit -> }
val listFun = { (l: List<String>) : List<String> -> l }
val mutableListFun = { (l: MutableList<Double>) : MutableList<Int> -> null!! }
val extensionFun = { Any.() : Unit -> }
val extensionWithArgFun = { Long.(x: Any) : Date -> Date() }
fun box(): String {
assertGenericSuper("jet.FunctionImpl0<jet.Unit>", unitFun)
assertGenericSuper("jet.FunctionImpl0<java.lang.Integer>", intFun)
assertGenericSuper("jet.FunctionImpl1<java.lang.String, jet.Unit>", stringParamFun)
assertGenericSuper("jet.FunctionImpl1<java.util.List, java.util.List>", listFun)
assertGenericSuper("jet.FunctionImpl0<? extends jet.Unit>", unitFun)
assertGenericSuper("jet.FunctionImpl0<? extends java.lang.Integer>", intFun)
assertGenericSuper("jet.FunctionImpl1<? super java.lang.String, ? extends jet.Unit>", stringParamFun)
assertGenericSuper("jet.FunctionImpl1<? super java.util.List<? extends java.lang.String>, ? extends java.util.List<? extends java.lang.String>>", listFun)
assertGenericSuper("jet.FunctionImpl1<? super java.util.List<java.lang.Double>, ? extends java.util.List<java.lang.Integer>>", mutableListFun)
assertGenericSuper("jet.ExtensionFunctionImpl0<java.lang.Object, jet.Unit>", extensionFun)
assertGenericSuper("jet.ExtensionFunctionImpl1<java.lang.Long, java.lang.Object, java.util.Date>", extensionWithArgFun)
assertGenericSuper("jet.ExtensionFunctionImpl0<? super java.lang.Object, ? extends jet.Unit>", extensionFun)
assertGenericSuper("jet.ExtensionFunctionImpl1<? super java.lang.Long, ? super java.lang.Object, ? extends java.util.Date>", extensionWithArgFun)
return "OK"
}