[NI] Support SAM conversions in backend for special expressions
This commit is contained in:
+6
@@ -881,6 +881,9 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
DeclarationDescriptor operationDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference());
|
||||
if (!(operationDescriptor instanceof FunctionDescriptor)) return;
|
||||
|
||||
ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(expression, bindingContext);
|
||||
if (resolvedCall != null) recordSamValueForNewInference(resolvedCall);
|
||||
|
||||
FunctionDescriptor original = SamCodegenUtil.getOriginalIfSamAdapter((FunctionDescriptor) operationDescriptor);
|
||||
if (original == null) return;
|
||||
|
||||
@@ -903,6 +906,9 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
DeclarationDescriptor operationDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
||||
if (!(operationDescriptor instanceof FunctionDescriptor)) return;
|
||||
|
||||
ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(expression, bindingContext);
|
||||
if (resolvedCall != null) recordSamValueForNewInference(resolvedCall);
|
||||
|
||||
boolean isSetter = operationDescriptor.getName().asString().equals("set");
|
||||
FunctionDescriptor original = SamCodegenUtil.getOriginalIfSamAdapter((FunctionDescriptor) operationDescriptor);
|
||||
if (original == null) return;
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
// FILE: example/Hello.java
|
||||
|
||||
package example;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Hello<A> {
|
||||
void invoke(A a);
|
||||
}
|
||||
|
||||
// FILE: example/SomeJavaClass.java
|
||||
package example;
|
||||
|
||||
public class SomeJavaClass<A> {
|
||||
public void someFunction(Hello<A> hello) {
|
||||
((Hello)hello).invoke("OK");
|
||||
}
|
||||
|
||||
public SomeJavaClass<A> plus(Hello<A> hello) {
|
||||
((Hello)hello).invoke("OK");
|
||||
return this;
|
||||
}
|
||||
|
||||
public void get(Hello<A> hello) {
|
||||
((Hello)hello).invoke("OK");
|
||||
}
|
||||
|
||||
public void set(int i, Hello<A> hello) {
|
||||
((Hello)hello).invoke("OK");
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import example.SomeJavaClass
|
||||
|
||||
fun box(): String {
|
||||
var a: SomeJavaClass<out String> = SomeJavaClass()
|
||||
|
||||
var result = "fail"
|
||||
|
||||
a.someFunction {
|
||||
result = it
|
||||
}
|
||||
|
||||
if (result != "OK") return "fail 1: $result"
|
||||
result = "fail"
|
||||
|
||||
a + {
|
||||
result = it
|
||||
}
|
||||
|
||||
if (result != "OK") return "fail 2: $result"
|
||||
result = "fail"
|
||||
|
||||
a[{
|
||||
result = it
|
||||
}]
|
||||
|
||||
if (result != "OK") return "fail 3: $result"
|
||||
|
||||
result = "fail"
|
||||
|
||||
a += {
|
||||
result = it
|
||||
}
|
||||
|
||||
if (result != "OK") return "fail 4: $result"
|
||||
|
||||
result = "fail"
|
||||
|
||||
a[0] = { result = it }
|
||||
|
||||
if (result != "OK") return "fail 5: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -13491,6 +13491,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamProjectedOut.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericSamProjectedOutWithNewInference.kt")
|
||||
public void testGenericSamProjectedOutWithNewInference() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamProjectedOutWithNewInference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaInstanceOf.kt")
|
||||
public void testLambdaInstanceOf() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
|
||||
|
||||
+5
@@ -13491,6 +13491,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamProjectedOut.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericSamProjectedOutWithNewInference.kt")
|
||||
public void testGenericSamProjectedOutWithNewInference() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamProjectedOutWithNewInference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaInstanceOf.kt")
|
||||
public void testLambdaInstanceOf() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
|
||||
|
||||
+5
@@ -13496,6 +13496,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamProjectedOut.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericSamProjectedOutWithNewInference.kt")
|
||||
public void testGenericSamProjectedOutWithNewInference() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/genericSamProjectedOutWithNewInference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaInstanceOf.kt")
|
||||
public void testLambdaInstanceOf() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/lambdaInstanceOf.kt");
|
||||
|
||||
Reference in New Issue
Block a user