JS backend: tests for reflection support
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
|
||||
public abstract class AbstractCallableReferenceTest extends SingleFileTranslationTest {
|
||||
|
||||
public AbstractCallableReferenceTest(@NotNull String main) {
|
||||
super("callableReference/" + main);
|
||||
}
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
public final class FunctionCallableReferenceTest extends AbstractCallableReferenceTest {
|
||||
|
||||
public FunctionCallableReferenceTest() {
|
||||
super("function/");
|
||||
}
|
||||
|
||||
public void testTopLevelFromClass() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testTopLevelFromExtension() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testTopLevelFromTopLevelStringNoArgs() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testTopLevelFromTopLevelWithArg() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testTopLevelFromTopLevelViaFunCall() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testClassMemberFromClass() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testClassMemberFromExtension() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testClassMemberFromTopLevelStringNoArgs() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testClassMemberFromTopLevelStringOneStringArg() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testClassMemberFromTopLevelUnitNoArgs() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testClassMemberFromTopLevelUnitOneStringArg() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testExtensionFromTopLevel() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testExtensionFromClass() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testExtensionFromExtension() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testExtensionFromTopLevelStringNoArgs() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testExtensionFromTopLevelStringOneStringArg() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testExtensionFromTopLevelUnitNoArgs() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testExtensionFromTopLevelUnitOneStringArg() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testConstructorFromTopLevelNoArgs() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testConstructorFromTopLevelOneStringArg() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testConstructorsWithArgs() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testAbstractClassMember() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testClassMemberOverridden() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testClassMemberOverriddenInObject() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testClassMemberAndExtension() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testClassMemberAndExtensionCompatibility() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testLocalAndTopLevelExtensions() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testClosureWithSideEffect() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testExtension() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testExtensionToPrimitive() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testExtensionWithClosure() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testLocalLocal() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testRecursiveClosure() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testUnitWithSideEffect() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testSimple() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testSimpleClosure() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testSimpleWithArg() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testStringNativeExtension() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
/*
|
||||
public void testBooleanNotIntrinsic() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -38,6 +38,10 @@ public class MultiPackageTest extends MultipleFilesTranslationTest {
|
||||
checkFooBoxIsTrue("packageVariableVisibleFromOtherPackage");
|
||||
}
|
||||
|
||||
public void testReflectionFromOtherPackage() throws Exception {
|
||||
checkFooBoxIsTrue("reflectionFromOtherPackage");
|
||||
}
|
||||
|
||||
public void testNestedPackageFunctionCalledFromOtherPackage() throws Exception {
|
||||
runMultiFileTest("nestedPackageFunctionCalledFromOtherPackage", "a.foo", TEST_FUNCTION, true);
|
||||
}
|
||||
|
||||
@@ -89,11 +89,31 @@ public final class NativeInteropTest extends SingleFileTranslationTest {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testNativeExtensionLikeMember() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testPassExtLambdaToNative() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testPassMemberOrExtToNative() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testPassExtLambdaFromNative() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testPassMemberOrExtFromNative() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testPassTopLevelOrLocalFunctionToNative() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testPassTopLevelFunctionFromNative() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
public class PropertyCallableReferenceTest extends AbstractCallableReferenceTest {
|
||||
|
||||
public PropertyCallableReferenceTest() {
|
||||
super("property/");
|
||||
}
|
||||
|
||||
public void testTopLevelVar() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testExtensionProperty() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testMemberProperty() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testAccessViaSubclass() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testDelegated() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testDelegatedMutable() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testKClassInstanceIsInitializedFirst() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testOverriddenInSubclass() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testSimpleExtension() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testSimpleMember() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testSimpleMutableExtension() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testSimpleMutableMember() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testSimpleMutableTopLevel() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testSimpleTopLevel() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
abstract class A {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String = B().(A::foo)()
|
||||
@@ -0,0 +1,8 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
if (true.(Boolean::not)() != false) return "Fail 1"
|
||||
if (false.(Boolean::not)() != true) return "Fail 2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
val s = "sA"
|
||||
fun memBar(other: String): String = s +":memBar:" + other
|
||||
}
|
||||
|
||||
fun A.extBar(other: String):String = s + ":extBar:" + other
|
||||
|
||||
fun box():String {
|
||||
fun A.locExtBar(other: String):String = s + ":locExtBar:" + other
|
||||
|
||||
val a = A()
|
||||
|
||||
var r = a.(A::memBar)("!!")
|
||||
if (r != "sA:memBar:!!") return r
|
||||
|
||||
r = a.(A::extBar)("!!")
|
||||
if (r != "sA:extBar:!!") return r
|
||||
|
||||
r = a.(A::locExtBar)("!!")
|
||||
if (r != "sA:locExtBar:!!") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package foo
|
||||
|
||||
fun run(a: A, arg: String, funRef:A.(String) -> String): String {
|
||||
return a.(funRef)(arg)
|
||||
}
|
||||
|
||||
class A {
|
||||
val s = "sA"
|
||||
fun memBar(other: String): String = s +":memBar:" + other
|
||||
}
|
||||
|
||||
fun A.extBar(other: String):String = s + ":extBar:" + other
|
||||
|
||||
fun box():String {
|
||||
fun A.locExtBar(other: String):String = s + ":locExtBar:" + other
|
||||
|
||||
val a = A()
|
||||
|
||||
var r = run(a, "!!", A::memBar)
|
||||
if (r != "sA:memBar:!!") return r
|
||||
|
||||
r = run(a, "!!", A::extBar)
|
||||
if (r != "sA:extBar:!!") return r
|
||||
|
||||
r = run(a, "!!", A::locExtBar)
|
||||
if (r != "sA:locExtBar:!!") return r
|
||||
|
||||
r = run(a, "!!") {A.(other:String):String -> s + ":literal:" + other }
|
||||
if (r != "sA:literal:!!") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun bar(k: Int) = k
|
||||
|
||||
fun result() = this.(::bar)(111)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A().result()
|
||||
if (result != 111) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun o() = 111
|
||||
fun k(k: Int) = k
|
||||
}
|
||||
|
||||
fun A.bar() = this.(::o)() + this.(A::k)(222)
|
||||
|
||||
fun box(): String {
|
||||
val result = A().bar()
|
||||
if (result != 333) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, funRef:A.() -> String): String {
|
||||
return arg1.funRef()
|
||||
}
|
||||
|
||||
class A {
|
||||
fun foo() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = A().x()
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(A(), A::foo)
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, arg2: String, funRef:A.(String) -> String): String {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A {
|
||||
fun foo(result: String):String = result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = A().x("OK")
|
||||
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(A(), "OK", A::foo)
|
||||
if (r != "OK") return r
|
||||
return "OK"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, funRef:A.() -> Unit): Unit {
|
||||
return arg1.funRef()
|
||||
}
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
|
||||
fun foo() {
|
||||
result = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
a.x()
|
||||
var r = a.result
|
||||
if (r != "OK") return r
|
||||
|
||||
val a1 = A()
|
||||
run(a1, A::foo)
|
||||
r = a.result
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, arg2: String, funRef:A.(String) -> Unit): Unit {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
|
||||
fun foo(newResult: String) {
|
||||
result = newResult
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
a.x("OK")
|
||||
var r = a.result
|
||||
if (r != "OK") return r
|
||||
|
||||
val a1 = A()
|
||||
run(a1, "OK", A::foo)
|
||||
r = a1.result
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
open fun foo(a:String,b:String): String = "fooA:" + a + b
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo(a:String,b:String): String = "fooB:" + a + b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
var ref = A::foo
|
||||
val result = b.(ref)("1", "2")
|
||||
return (if (result == "fooB:12") "OK" else result)
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
open fun foo(a:String,b:String): String = "fooA:" + a + b
|
||||
}
|
||||
|
||||
object B : A() {
|
||||
override fun foo(a:String,b:String): String = "fooB:" + a + b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var ref = B::foo
|
||||
val result = B.(ref)("1", "2")
|
||||
return (if (result == "fooB:12") "OK" else result)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var result = "Fail"
|
||||
|
||||
fun changeToOK() { result = "OK" }
|
||||
|
||||
val ok = ::changeToOK
|
||||
ok()
|
||||
return result
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
var result = "OK"
|
||||
}
|
||||
|
||||
fun box() = (::A)().result
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A(val result: String)
|
||||
|
||||
fun box() = (::A)("OK").result
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
class A(val x:Int) {
|
||||
var s = "sA"
|
||||
{
|
||||
s += ":init:" + x
|
||||
}
|
||||
}
|
||||
|
||||
class B(val arg1:String, val arg2:String) {
|
||||
var msg = ""
|
||||
{
|
||||
msg = arg1 + arg2
|
||||
}
|
||||
}
|
||||
|
||||
fun box():String {
|
||||
val ref = ::A
|
||||
var result = ref(1).s + (::B)("23", "45").msg
|
||||
return (if (result == "sA:init:12345") "OK" else result)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
fun A.foo() = "OK"
|
||||
return A().(A::foo)()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun result() = this.(::bar)("OK")
|
||||
}
|
||||
|
||||
fun A.bar(x: String) = x
|
||||
|
||||
fun box() = A().result()
|
||||
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun A.foo() = this.(A::bar)("OK")
|
||||
|
||||
fun A.bar(x: String) = x
|
||||
|
||||
fun box() = A().foo()
|
||||
@@ -0,0 +1,25 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun <T> run(arg1: A, arg2: T, funRef:A.(T) -> T): T {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A {
|
||||
var xx: Int = 100
|
||||
}
|
||||
|
||||
fun A.bar(x: Int): Int {
|
||||
this.xx = this.xx * 2
|
||||
return x
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val funRef = A::bar
|
||||
val obj = A()
|
||||
var result = obj.(funRef)(25)
|
||||
if (result != 25 || obj.xx != 200) return false
|
||||
|
||||
result = run(A(), 25, funRef)
|
||||
return result == 25 && obj.xx == 200
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, funRef:A.() -> String): String {
|
||||
return arg1.funRef()
|
||||
}
|
||||
|
||||
class A
|
||||
|
||||
fun A.foo() = "OK"
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = A().x()
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(A(), A::foo)
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, arg2: String, funRef:A.(String) -> String): String {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A
|
||||
|
||||
fun A.foo(result: String) = result
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = A().x("OK")
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(A(), "OK", A::foo)
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, funRef:A.() -> Unit): Unit {
|
||||
return arg1.funRef()
|
||||
}
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
}
|
||||
|
||||
fun A.foo() {
|
||||
result = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
a.x()
|
||||
|
||||
if (a.result != "OK") return a.result
|
||||
|
||||
val a1 = A()
|
||||
run(a1, A::foo)
|
||||
return a.result
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, arg2: String, funRef:A.(String) -> Unit): Unit {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
}
|
||||
|
||||
fun A.foo(newResult: String) {
|
||||
result = newResult
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
a.x("OK")
|
||||
|
||||
if (a.result != "OK") return a.result
|
||||
|
||||
val a1 = A()
|
||||
run(a1, "OK", A::foo)
|
||||
return a.result
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun Int.is42With(that: Int) = this + 2 * that == 42
|
||||
return if (16.(Int::is42With)(13)) "OK" else "Fail"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
var result = "Fail"
|
||||
|
||||
fun A.ext() { result = "OK" }
|
||||
|
||||
val f = A::ext
|
||||
A().f()
|
||||
return result
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
fun Int.sum0(other: Int): Int = this + other;
|
||||
|
||||
fun box(): String {
|
||||
fun Int.sum1(other: Int): Int = this + other
|
||||
|
||||
val sum2 = {Int.(other : Int) : Int -> this + other}
|
||||
|
||||
var x = 10
|
||||
x = x.sum0(5)
|
||||
x = x.sum1(5)
|
||||
x = x.sum2(5)
|
||||
|
||||
var y = 10
|
||||
y = y.(Int::sum0)(5)
|
||||
y = y.(Int::sum1)(5)
|
||||
y = y.sum2(5)
|
||||
|
||||
var result:String = (if (x == y && x == 25) "OK" else "x=${x} y=${y}")
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun foo(): String {
|
||||
fun bar() = "OK"
|
||||
val ref = ::bar
|
||||
return ref()
|
||||
}
|
||||
|
||||
val ref = ::foo
|
||||
return ref()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun foo(until: Int): String {
|
||||
fun bar(x: Int): String =
|
||||
if (x == until) "OK" else bar(x + 1)
|
||||
return (::bar)(0)
|
||||
}
|
||||
|
||||
fun box() = foo(10)
|
||||
@@ -0,0 +1,7 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun foo() = "OK"
|
||||
return (::foo)()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val result = "OK"
|
||||
|
||||
fun foo() = result
|
||||
|
||||
return (::foo)()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun foo(s: String) = s
|
||||
return (::foo)("OK")
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var s = "abc"
|
||||
assertEquals("ABC", s.(String::toUpperCase)())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun <T> run(arg1: T, arg2: T, funRef:(T,T) -> T): T {
|
||||
return funRef(arg1, arg2)
|
||||
}
|
||||
|
||||
fun tmp(o: Int, k: Int) = o + k
|
||||
|
||||
class A {
|
||||
fun bar() = (::tmp)(111, 222)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A().bar()
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
var r = run(111, 222, ::tmp)
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun <T> run(arg1: T, arg2: T, funRef:(T,T) -> T): T {
|
||||
return funRef(arg1, arg2)
|
||||
}
|
||||
|
||||
fun tmp(o: Int, k: Int) = o + k
|
||||
|
||||
class A
|
||||
|
||||
fun A.bar() = (::tmp)(111, 222)
|
||||
|
||||
fun box(): String {
|
||||
val result = A().bar()
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
var r = run(111, 222, ::tmp)
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(funRef:() -> String): String {
|
||||
return funRef()
|
||||
}
|
||||
|
||||
fun bar() = "OK"
|
||||
|
||||
fun box(): String {
|
||||
val x = ::bar
|
||||
|
||||
var r = x()
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(::bar)
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg: Int, funRef:(Int) -> Int): Int {
|
||||
return funRef(arg)
|
||||
}
|
||||
|
||||
fun inc(x: Int) = x + 1
|
||||
|
||||
fun tmp():Function1<Int, Int> {
|
||||
return ::inc
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
if (tmp()(5) != 6) return false
|
||||
|
||||
if (run(5, tmp()) != 6) return false
|
||||
|
||||
return true
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg: Int, funRef:(Int) -> Int): Int {
|
||||
return funRef(arg)
|
||||
}
|
||||
fun inc(x: Int) = x + 1
|
||||
|
||||
fun box(): Boolean {
|
||||
val funRef = ::inc
|
||||
if (funRef(5) != 6) return false
|
||||
|
||||
if (run(5, funRef) != 6) return false
|
||||
|
||||
if (run(5) {x -> x + 1} != 6) return false
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
var state = 23
|
||||
|
||||
fun box(): String {
|
||||
fun incrementState(inc: Int) {
|
||||
state += inc
|
||||
}
|
||||
|
||||
val inc = ::incrementState
|
||||
inc(12)
|
||||
inc(-5)
|
||||
inc(27)
|
||||
inc(-15)
|
||||
|
||||
return if (state == 42) "OK" else "Fail $state"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
abstract class Base {
|
||||
val result = "OK"
|
||||
}
|
||||
|
||||
class Derived : Base()
|
||||
|
||||
fun box(): String {
|
||||
return (Base::result).get(Derived())
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
object NumberDecrypter {
|
||||
fun get(instance: Any?, data: PropertyMetadata) = when (data.name) {
|
||||
"four" -> 4
|
||||
"two" -> 2
|
||||
else -> throw Exception()
|
||||
}
|
||||
}
|
||||
|
||||
val four: Int by NumberDecrypter
|
||||
|
||||
class A {
|
||||
val two: Int by NumberDecrypter
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = ::four.get()
|
||||
if (x != 4) return "Fail x: $x"
|
||||
val a = A()
|
||||
val y = A::two.get(a)
|
||||
if (y != 2) return "Fail y: $y"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
object Delegate {
|
||||
var value = "lol"
|
||||
|
||||
fun get(instance: Any?, data: PropertyMetadata): String {
|
||||
return value
|
||||
}
|
||||
|
||||
fun set(instance: Any?, data: PropertyMetadata, newValue: String) {
|
||||
value = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var result: String by Delegate
|
||||
|
||||
fun box(): String {
|
||||
val f = ::result
|
||||
if (f.get() != "lol") return "Fail 1: {$f.get()}"
|
||||
Delegate.value = "rofl"
|
||||
if (f.get() != "rofl") return "Fail 2: {$f.get()}"
|
||||
f.set("OK")
|
||||
return f.get()
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package foo
|
||||
|
||||
|
||||
open class A(var msg:String) {
|
||||
}
|
||||
|
||||
class B:A("FromB") {
|
||||
}
|
||||
|
||||
var global:String = ""
|
||||
|
||||
var A.ext:String
|
||||
get() = ":A.ext ${this.msg}:"
|
||||
set(value) { global = ":A.ext ${value}" }
|
||||
|
||||
var B.ext:String
|
||||
get() = ":B.ext ${this.msg}:"
|
||||
set(value) { global = ":B.ext ${value}" }
|
||||
|
||||
fun box(): String {
|
||||
val a = A("Test")
|
||||
|
||||
var refAExt = A::ext
|
||||
var refBExt = B::ext
|
||||
|
||||
assertEquals("ext", refAExt.name)
|
||||
assertEquals("ext", refBExt.name)
|
||||
|
||||
assertEquals(":A.ext Test:", refAExt.get(a))
|
||||
assertEquals(":B.ext FromB:", refBExt.get(B()))
|
||||
|
||||
refAExt.set(a, "newA")
|
||||
assertEquals(":A.ext newA", global)
|
||||
|
||||
global = ""
|
||||
refBExt.set(B(), "newB")
|
||||
assertEquals(":B.ext newB", global)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
import kotlin.reflect.KMemberProperty
|
||||
|
||||
class A {
|
||||
class object {
|
||||
val ref: KMemberProperty<A, String> = A::foo
|
||||
}
|
||||
|
||||
val foo: String = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return A.ref.get(A())
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
open class A(var msg:String) {
|
||||
open var prop:String = "initA"
|
||||
}
|
||||
|
||||
class B:A("FromB") {
|
||||
override var prop:String = "initB"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var refAProp = A::prop
|
||||
var refBProp = B::prop
|
||||
|
||||
assertEquals("prop", refAProp.name)
|
||||
assertEquals("prop", refBProp.name)
|
||||
|
||||
val a = A("Test")
|
||||
assertEquals("initA", refAProp.get(a))
|
||||
|
||||
refAProp.set(a, "newPropA")
|
||||
assertEquals("newPropA", a.prop)
|
||||
|
||||
val a1 = B()
|
||||
assertEquals("initB", refAProp.get(a1))
|
||||
|
||||
refAProp.set(a1, "newPropB")
|
||||
assertEquals("newPropB", a1.prop)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
open class Base {
|
||||
open val foo = "Base"
|
||||
}
|
||||
|
||||
class Derived : Base() {
|
||||
override val foo = "OK"
|
||||
}
|
||||
|
||||
fun box() = (Base::foo).get(Derived())
|
||||
@@ -0,0 +1,15 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
val String.id: String
|
||||
get() = this
|
||||
|
||||
fun box(): String {
|
||||
val pr = String::id
|
||||
|
||||
if (pr["123"] != "123") return "Fail value: ${pr["123"]}"
|
||||
|
||||
if (pr.name != "id") return "Fail name: ${pr.name}"
|
||||
|
||||
return pr.get("OK")
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
class A(val x: Int)
|
||||
|
||||
fun box(): String {
|
||||
val p = A::x
|
||||
if (p.get(A(42)) != 42) return "Fail 1"
|
||||
if (p.get(A(-1)) != -1) return "Fail 2"
|
||||
if (p.name != "x") return "Fail 3"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
var storage = 0
|
||||
|
||||
var Int.foo: Int
|
||||
get() {
|
||||
return this + storage
|
||||
}
|
||||
set(value) {
|
||||
storage = this + value
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val pr = Int::foo
|
||||
if (pr.get(42) != 42) return "Fail 1: ${pr[42]}"
|
||||
pr.set(200, 39)
|
||||
if (pr.get(-239) != 0) return "Fail 2: ${pr[-239]}"
|
||||
if (storage != 239) return "Fail 3: $storage"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
data class Box(var value: String)
|
||||
|
||||
fun box(): String {
|
||||
val o = Box("lorem")
|
||||
val prop = Box::value
|
||||
|
||||
if (prop.get(o) != "lorem") return "Fail 1: ${prop[o]}"
|
||||
prop.set(o, "ipsum")
|
||||
if (prop.get(o) != "ipsum") return "Fail 2: ${prop[o]}"
|
||||
if (o.value != "ipsum") return "Fail 3: ${o.value}"
|
||||
o.value = "dolor"
|
||||
if (prop.get(o) != "dolor") return "Fail 4: ${prop.get(o)}"
|
||||
if ("$o" != "Box(value=dolor)") return "Fail 5: $o"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
data class Box(val value: String)
|
||||
|
||||
var pr = Box("first")
|
||||
|
||||
fun box(): String {
|
||||
val property = ::pr
|
||||
if (property.get() != Box("first")) return "Fail value: ${property.get()}"
|
||||
if (property.name != "pr") return "Fail name: ${property.name}"
|
||||
property.set(Box("second"))
|
||||
if (property.get().value != "second") return "Fail value 2: ${property.get()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
data class Box(val value: String)
|
||||
|
||||
val foo = Box("lol")
|
||||
|
||||
fun box(): String {
|
||||
val property = ::foo
|
||||
if (property.get() != Box("lol")) return "Fail value: ${property.get()}"
|
||||
if (property.name != "foo") return "Fail name: ${property.name}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
var x = 1
|
||||
|
||||
val y = 2
|
||||
|
||||
fun box(): String {
|
||||
var refX = ::x
|
||||
assertEquals(1, refX.get())
|
||||
assertEquals("x", refX.name)
|
||||
|
||||
refX.set(100)
|
||||
assertEquals(100, x)
|
||||
|
||||
var refY = ::y
|
||||
assertEquals(2, refY.get())
|
||||
assertEquals("y", refY.name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package bar
|
||||
|
||||
fun topLevelFun(s: String) = "topLevelFun: ${s}";
|
||||
|
||||
var topLevelVar = 100
|
||||
|
||||
val topLevelVal = 200
|
||||
|
||||
class A(val v: String) {
|
||||
fun memA(s: String) = "memA: ${v} ${s}"
|
||||
var propVar: Int = 1000
|
||||
val propVal: Int = 2000
|
||||
var text: String = "text"
|
||||
}
|
||||
|
||||
fun A.ext1(s: String): String = "A.ext1: ${this.v} ${s}"
|
||||
|
||||
var A.extProp: String
|
||||
get() = "${this.text}"
|
||||
set(value) {
|
||||
this.text = value
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package foo
|
||||
|
||||
import bar.*
|
||||
|
||||
fun A.ext2(s: String): String = "A.ext2: ${this.v} ${s}"
|
||||
|
||||
fun box(): Boolean {
|
||||
|
||||
assertEquals("topLevelFun: A", (::topLevelFun)("A"))
|
||||
assertEquals("A.ext1: test B", A("test").(A::ext1)("B"))
|
||||
assertEquals("A.ext2: test B", A("test").(A::ext2)("B"))
|
||||
assertEquals("memA: test C", A("test").(A::memA)("C"))
|
||||
|
||||
assertEquals(100, ::topLevelVar.get())
|
||||
::topLevelVar.set(500)
|
||||
assertEquals(500, ::topLevelVar.get())
|
||||
assertEquals(200, ::topLevelVal.get())
|
||||
val a = A("test")
|
||||
assertEquals(1000, (A::propVar).get(a))
|
||||
A::propVar.set(a, 5000)
|
||||
assertEquals(5000, (A::propVar).get(a))
|
||||
assertEquals(2000, (A::propVal).get(a))
|
||||
|
||||
assertEquals("text", (A::extProp).get(a))
|
||||
(A::extProp).set(a, "new text")
|
||||
assertEquals("new text", (A::extProp).get(a))
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
open class A(val value: String) {
|
||||
}
|
||||
|
||||
class B : A("B") {
|
||||
fun bar(): String = "B.bar ${value}"
|
||||
var prop: String = "B prop"
|
||||
}
|
||||
|
||||
native fun A.bar(): String = js.noImpl
|
||||
|
||||
native var A.prop: String
|
||||
get() = js.noImpl
|
||||
set(value) = js.noImpl
|
||||
|
||||
fun box(): String {
|
||||
var a: A = A("A")
|
||||
val b: B = B()
|
||||
|
||||
assertEquals("A.bar A", a.bar())
|
||||
assertEquals("B.bar B", b.bar())
|
||||
|
||||
assertEquals("A.bar A", a.(A::bar)())
|
||||
assertEquals("B.bar B", b.(A::bar)())
|
||||
|
||||
a.prop = "prop"
|
||||
assertEquals("prop", a.prop)
|
||||
assertEquals("prop", (A::prop).get(a))
|
||||
|
||||
a = b
|
||||
assertEquals("B.bar B", a.bar())
|
||||
assertEquals("B.bar B", a.(A::bar)())
|
||||
|
||||
assertEquals("B prop", a.prop)
|
||||
assertEquals("B prop", (A::prop).get(a))
|
||||
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
class A(val v: String) {
|
||||
fun m(i:Int, s:String): String = js.noImpl
|
||||
}
|
||||
native
|
||||
fun A.nativeExt(i:Int, s:String): String = js.noImpl
|
||||
|
||||
native("nativeExt2AnotherName")
|
||||
fun A.nativeExt2(i:Int, s:String): String = js.noImpl
|
||||
|
||||
fun bar(a: A, extLambda: A.(Int, String) -> String): String = a.(extLambda)(4, "boo")
|
||||
|
||||
fun box(): String {
|
||||
val a = A("test")
|
||||
|
||||
assertEquals("A.m test 4 boo", a.m(4, "boo"))
|
||||
assertEquals("A.m test 4 boo", bar(a, A::m))
|
||||
|
||||
assertEquals("nativeExt test 4 boo", a.nativeExt(4, "boo"))
|
||||
assertEquals("nativeExt test 4 boo", bar(a, A::nativeExt))
|
||||
|
||||
assertEquals("nativeExt2 test 4 boo", a.nativeExt2(4, "boo"))
|
||||
assertEquals("nativeExt2 test 4 boo", bar(a, A::nativeExt2))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package foo
|
||||
|
||||
open class A(val v: String) {
|
||||
open fun m(i:Int, s:String): String = "A.m ${this.v} $i $s"
|
||||
}
|
||||
|
||||
class B(v: String): A(v) {
|
||||
override fun m(i:Int, s:String): String = "B.m ${this.v} $i $s"
|
||||
}
|
||||
|
||||
native
|
||||
fun bar(a: A, extLambda: A.(Int, String) -> String): String = noImpl
|
||||
|
||||
fun A.topLevelExt(i:Int, s:String): String = "A::topLevelExt ${this.v} $i $s"
|
||||
|
||||
fun box(): String {
|
||||
val a = A("test")
|
||||
|
||||
var r = bar(a) { i, s -> "${this.v} $i $s"}
|
||||
if (r != "test 4 boo") return r
|
||||
|
||||
fun A.LocalExt(i:Int, s:String): String = "A::LocalExt ${this.v} $i $s"
|
||||
|
||||
r = bar(a, A::topLevelExt)
|
||||
if (r != "A::topLevelExt test 4 boo") return r
|
||||
|
||||
r = bar(a, A::LocalExt)
|
||||
if (r != "A::LocalExt test 4 boo") return r
|
||||
|
||||
r = bar(a, A::m)
|
||||
if (r != "A.m test 4 boo") return r
|
||||
|
||||
val b = B("test")
|
||||
r = bar(b, A::m)
|
||||
if (r != "B.m test 4 boo") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
fun nativeFun(i:Int, s:String): String = js.noImpl
|
||||
|
||||
fun bar(funRef: (Int, String) -> String): String = funRef(4, "boo")
|
||||
|
||||
fun box(): String {
|
||||
var r = nativeFun(4, "boo")
|
||||
if (r != "nativeFun 4 boo") return r
|
||||
|
||||
r = bar(::nativeFun)
|
||||
if (r != "nativeFun 4 boo") return r
|
||||
|
||||
r = (::nativeFun)(4, "boo")
|
||||
if (r != "nativeFun 4 boo") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
fun run(i:Int, s:String, funRef: (Int, String) -> String): String = noImpl
|
||||
|
||||
fun funTopLevel(i:Int, s:String): String = "funTopLevel $i $s"
|
||||
|
||||
fun box(): String {
|
||||
fun funLocal(i:Int, s:String): String = "funLocal $i $s"
|
||||
|
||||
// Check for lambda
|
||||
var r = run(4, "boo") { i, s -> "$i $s"}
|
||||
if (r != "4 boo") return r
|
||||
|
||||
r = run(4, "boo", ::funTopLevel)
|
||||
if (r != "funTopLevel 4 boo") return r
|
||||
|
||||
r = run(4, "boo", ::funLocal)
|
||||
if (r != "funLocal 4 boo") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
function A(value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
A.prototype.bar = function() { return "A.bar " + this.value; };
|
||||
@@ -0,0 +1,14 @@
|
||||
function A(v) {
|
||||
this.v = v;
|
||||
this.m = function (i, s) {
|
||||
return "A.m " + v + " " + i + " " + s;
|
||||
}
|
||||
}
|
||||
|
||||
A.prototype.nativeExt = function (i, s) {
|
||||
return "nativeExt " + this.v + " " + i + " " + s;
|
||||
};
|
||||
|
||||
A.prototype.nativeExt2AnotherName = function (i, s) {
|
||||
return "nativeExt2 " + this.v + " " + i + " " + s;
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
function bar(a, extLambda) {
|
||||
return extLambda.call(a, 4, "boo")
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function nativeFun(i, s) {
|
||||
return "nativeFun " + i + " " + s;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
function run(arg0, arg1, funRef) {
|
||||
return funRef(arg0, arg1)
|
||||
}
|
||||
Reference in New Issue
Block a user