[IR] Support function references
Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com> #KT-1179
This commit is contained in:
committed by
Space Team
parent
b45f2baff5
commit
89d5592622
@@ -0,0 +1,33 @@
|
||||
// CHECK_BYTECODE_LISTING
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WORKS_WHEN_VALUE_CLASS
|
||||
// LANGUAGE: +ValueClasses
|
||||
|
||||
@JvmInline
|
||||
value class DPoint(val x: Double, val y: Double) {
|
||||
fun f(z: Double) = x + y + z
|
||||
}
|
||||
|
||||
fun g(point: DPoint, z: Double) = point.f(z)
|
||||
|
||||
class A(val point: DPoint) {
|
||||
fun f(otherDPoint: DPoint, z: Double) = point.f(z) * otherDPoint.f(z)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val dPoint = DPoint(1.0, 2.0)
|
||||
val a = A(dPoint)
|
||||
|
||||
require((::DPoint)(1.0, 2.0) == dPoint)
|
||||
require((dPoint::f)(3.0) == 6.0)
|
||||
require((::g)(dPoint, 3.0) == 6.0)
|
||||
require((a::f)(dPoint, 3.0) == 36.0)
|
||||
|
||||
require((::DPoint)(1.0, DPoint(1.0, 2.0).y) == dPoint)
|
||||
require((dPoint::f)(DPoint(1.0, 3.0).y) == 6.0)
|
||||
require((::g)(dPoint, DPoint(1.0, 3.0).y) == 6.0)
|
||||
require((a::f)(dPoint, DPoint(1.0, 3.0).y) == 36.0)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
@kotlin.Metadata
|
||||
public final class A {
|
||||
// source: 'functionReferences.kt'
|
||||
private final field point-0: double
|
||||
private final field point-1: double
|
||||
public method <init>(p0: double, p1: double): void
|
||||
public final method f-GPBa7dw(p0: double, p1: double, p2: double): double
|
||||
public final @org.jetbrains.annotations.NotNull method getPoint(): DPoint
|
||||
public synthetic final method getPoint-0(): double
|
||||
public synthetic final method getPoint-1(): double
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline
|
||||
@kotlin.Metadata
|
||||
public final class DPoint {
|
||||
// source: 'functionReferences.kt'
|
||||
private final field field-0: double
|
||||
private final field field-1: double
|
||||
private synthetic method <init>(p0: double, p1: double): void
|
||||
public synthetic final static method box-impl(p0: double, p1: double): DPoint
|
||||
public final static method constructor-impl(p0: double, p1: double): void
|
||||
public method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: double, p1: double, p2: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: double, p1: double, p2: double, p3: double): boolean
|
||||
public final static method f-impl(p0: double, p1: double, p2: double): double
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: double, p1: double): int
|
||||
public @org.jetbrains.annotations.NotNull method toString(): java.lang.String
|
||||
public static method toString-impl(p0: double, p1: double): java.lang.String
|
||||
public synthetic final method unbox-impl-0(): double
|
||||
public synthetic final method unbox-impl-1(): double
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class FunctionReferencesKt {
|
||||
// source: 'functionReferences.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method g-GPBa7dw(p0: double, p1: double, p2: double): double
|
||||
}
|
||||
Reference in New Issue
Block a user