Forbidden old invokeExtension convention.

This commit is contained in:
Stanislav Erokhin
2015-10-16 21:25:25 +03:00
parent fc4b0a8121
commit 7d7d37719b
26 changed files with 157 additions and 126 deletions
@@ -1,20 +1,7 @@
// KT-3998 Infix call doesn't work for function literals and another classes which implements invoke convention (in JS backend)
package foo
class A(val s: String) {
fun A.invoke(a: A) = "${this.s} ${this@A.s} ${a.s}"
}
fun test1(): String {
val a = A("a")
val b = A("b")
val c = A("c")
val f = a.b(c) // works
val s = a b c //compiler crashes
return "$f | $s"
}
fun test2(): String {
fun test(): String {
val a: (@Extension Function2<*, *, *>).(@Extension Function2<*, *, *>)->String = { "a" }
val b: (@Extension Function2<*, *, *>).(@Extension Function2<*, *, *>)->String = {
val aa = this as @Extension Function2<Any?, Any?, Any?>;
@@ -29,8 +16,7 @@ fun test2(): String {
}
fun box(): String {
assertEquals("a b c | a b c", test1())
assertEquals("a b c | a b c", test2())
assertEquals("a b c | a b c", test())
return "OK"
}
@@ -4,6 +4,7 @@
* This led to runtime errors (see KT-7692), so the test is temporarily disabled.
*
* TODO: support inheritance from function types and re-enable this test
* NOTE: inheritance from extension function is forbidden now
*/
package foo
@@ -16,42 +17,24 @@ class Baz/* : Function2<Int, Boolean, String>*/ {
fun invoke(i: Int, b: Boolean) = "Baz.invoke($i, $b)"
}
class ExtBar/* : ExtensionFunction0<String, String>*/ {
fun String.invoke() = "ExtBar.invoke($this)"
}
class ExtBaz/* : ExtensionFunction2<String, Int, Boolean, String>*/ {
fun String.invoke(i: Int, b: Boolean) = "ExtBaz.invoke($this, $i, $b)"
}
class Mixed/* :
Function1<Int, String>,
Function2<Int, Boolean, String>,
ExtensionFunction1<Int, Boolean, String>,
ExtensionFunction2<Int, Int, Boolean, String>*/
Function2<Int, Boolean, String>*/
{
fun invoke(i: Int) = "Mixed.invoke($i)"
fun invoke(i: Int, b: Boolean) = "Mixed.invoke($i, $b)"
fun Int.invoke(b: Boolean) = "ext Mixed.invoke($this, $b)"
fun Int.invoke(i: Int, b: Boolean) = "ext Mixed.invoke($this, $i, $b)"
}
fun box(): String {
val bar = Bar()
val baz = Baz()
val extBar = ExtBar()
val extBaz = ExtBaz()
val mixed = Mixed()
assertEquals("Bar.invoke()", bar())
assertEquals("Baz.invoke(2, false)", baz(2, false))
assertEquals("ExtBar.invoke(2e2)", "2e2".extBar())
assertEquals("ExtBaz.invoke(29, 34, true)", "29".extBaz(34, true))
assertEquals("Mixed.invoke(45)", mixed(45))
assertEquals("Mixed.invoke(552, true)", mixed(552, true))
assertEquals("ext Mixed.invoke(21, true)", 21.mixed(true))
assertEquals("ext Mixed.invoke(29, 304, false)", 29.mixed(304, false))
return "OK"
}
@@ -1,12 +1,9 @@
package foo
class A
class B {
fun A.invoke(i: Int) = i
}
fun box(): Boolean {
val a = A()
val b = B()
val b = fun A.(i: Int) = i
return a.(b)(1) == 1
}