[IR] Support object-like interaction with MFVC function references
Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com> #KT-1179
This commit is contained in:
committed by
Space Team
parent
1660dc21b9
commit
c6e54e6433
@@ -15,6 +15,16 @@ class A(val point: DPoint) {
|
||||
fun f(otherDPoint: DPoint, z: Double) = point.f(z) * otherDPoint.f(z)
|
||||
}
|
||||
|
||||
fun consume(point1: DPoint, point2: DPoint, f: (DPoint, DPoint) -> DPoint) = f(point1, point2)
|
||||
|
||||
inline fun consumeInline(point1: DPoint, point2: DPoint, f: (DPoint, DPoint) -> DPoint) = f(point1, point2)
|
||||
|
||||
operator fun DPoint.plus(other: DPoint) = DPoint(this.x + other.x, this.y + other.y)
|
||||
|
||||
fun makeDPoint(x: Double, y: Double, maker: (Double, Double) -> DPoint) = maker(x, y)
|
||||
|
||||
inline fun makeDPointInline(x: Double, y: Double, maker: (Double, Double) -> DPoint) = maker(x, y)
|
||||
|
||||
fun box(): String {
|
||||
val dPoint = DPoint(1.0, 2.0)
|
||||
val a = A(dPoint)
|
||||
@@ -29,5 +39,17 @@ fun box(): String {
|
||||
require((::g)(dPoint, DPoint(1.0, 3.0).y) == 6.0)
|
||||
require((a::f)(dPoint, DPoint(1.0, 3.0).y) == 36.0)
|
||||
|
||||
require(consume(DPoint(1.0, 2.0), DPoint(3.0, 4.0), DPoint::plus) == DPoint(4.0, 6.0))
|
||||
require(consumeInline(DPoint(1.0, 2.0), DPoint(3.0, 4.0), DPoint::plus) == DPoint(4.0, 6.0))
|
||||
|
||||
require(makeDPoint(1.0, 2.0, ::DPoint) == DPoint(1.0, 2.0))
|
||||
require(makeDPointInline(1.0, 2.0, ::DPoint) == DPoint(1.0, 2.0))
|
||||
|
||||
require(::DPoint == ::DPoint)
|
||||
require(dPoint::f == dPoint::f)
|
||||
require(::g == ::g)
|
||||
require(a::f == a::f)
|
||||
require(DPoint::plus == DPoint::plus)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user