Inherit KProperty interfaces from function types
To be able to write the following: listOfStrings.map(String::length)
This commit is contained in:
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.modules.TargetId;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
@@ -538,9 +539,16 @@ public class InlineCodegen extends CallGenerator {
|
||||
}
|
||||
|
||||
/*lambda or callable reference*/
|
||||
public static boolean isInliningParameter(KtExpression expression, ValueParameterDescriptor valueParameterDescriptor) {
|
||||
public boolean isInliningParameter(KtExpression expression, ValueParameterDescriptor valueParameterDescriptor) {
|
||||
//TODO deparenthisise typed
|
||||
KtExpression deparenthesized = KtPsiUtil.deparenthesize(expression);
|
||||
|
||||
if (deparenthesized instanceof KtCallableReferenceExpression) {
|
||||
// TODO: support inline of property references passed to inlinable function parameters
|
||||
SimpleFunctionDescriptor functionReference = state.getBindingContext().get(BindingContext.FUNCTION, deparenthesized);
|
||||
if (functionReference == null) return false;
|
||||
}
|
||||
|
||||
return InlineUtil.isInlineLambdaParameter(valueParameterDescriptor) &&
|
||||
isInlinableParameterExpression(deparenthesized);
|
||||
}
|
||||
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
var state = ""
|
||||
|
||||
var topLevel: Int
|
||||
get() {
|
||||
state += "1"
|
||||
return 42
|
||||
}
|
||||
set(value) {
|
||||
throw AssertionError("Nooo")
|
||||
}
|
||||
|
||||
class A {
|
||||
val member: String
|
||||
get() {
|
||||
state += "2"
|
||||
return "42"
|
||||
}
|
||||
}
|
||||
|
||||
val A.ext: Any
|
||||
get() {
|
||||
state += "3"
|
||||
return this
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
(::topLevel)()
|
||||
(A::member)(A())
|
||||
(A::ext)(A())
|
||||
return if (state == "123") "OK" else "Fail $state"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import kotlin.reflect.declaredMemberProperties
|
||||
|
||||
class A(val foo: String)
|
||||
|
||||
fun box(): String {
|
||||
return (A::class.declaredMemberProperties.single()).invoke(A("OK")) as String
|
||||
}
|
||||
+12
@@ -816,6 +816,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("invokePropertyReference.kt")
|
||||
public void testInvokePropertyReference() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property/invokePropertyReference.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaBeanConvention.kt")
|
||||
public void testJavaBeanConvention() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property/javaBeanConvention.kt");
|
||||
@@ -4191,6 +4197,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("invokeKProperty.kt")
|
||||
public void testInvokeKProperty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/properties/invokeKProperty.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("memberAndMemberExtensionWithSameName.kt")
|
||||
public void testMemberAndMemberExtensionWithSameName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/properties/memberAndMemberExtensionWithSameName.kt");
|
||||
|
||||
Reference in New Issue
Block a user