AA FIR: build argument mapping for SAM conversion node

^KT-64910 fixed
This commit is contained in:
Jinseong Jeon
2024-01-11 22:42:08 -08:00
committed by teamcity
parent d6c9a492ad
commit e91e5db0ce
13 changed files with 390 additions and 1 deletions
@@ -766,6 +766,30 @@ public class Fe10IdeNormalAnalysisSourceModuleResolveCallTestGenerated extends A
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samConstructorCall.kt");
}
@Test
@TestMetadata("samFromJava_lambda.kt")
public void testSamFromJava_lambda() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samFromJava_lambda.kt");
}
@Test
@TestMetadata("samFromJava_methodReference.kt")
public void testSamFromJava_methodReference() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samFromJava_methodReference.kt");
}
@Test
@TestMetadata("samLambda.kt")
public void testSamLambda() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samLambda.kt");
}
@Test
@TestMetadata("samMethodReference.kt")
public void testSamMethodReference() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samMethodReference.kt");
}
@Test
@TestMetadata("simpleCallWithNonMatchingArgs.kt")
public void testSimpleCallWithNonMatchingArgs() throws Exception {
@@ -1343,7 +1343,10 @@ internal class KtFirCallResolver(
// For spread, named, and lambda arguments, the source is the KtValueArgument.
// For other arguments (including array indices), the source is the KtExpression.
return when (this) {
is FirSmartCastExpression -> originalExpression.realPsi as? KtExpression
is FirSamConversionExpression ->
expression.realPsi as? KtExpression
is FirSmartCastExpression ->
originalExpression.realPsi as? KtExpression
is FirNamedArgumentExpression, is FirSpreadArgumentExpression, is FirLambdaArgumentExpression ->
realPsi.safeAs<KtValueArgument>()?.getArgumentExpression()
else -> realPsi as? KtExpression
@@ -766,6 +766,30 @@ public class FirIdeNormalAnalysisSourceModuleResolveCallTestGenerated extends Ab
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samConstructorCall.kt");
}
@Test
@TestMetadata("samFromJava_lambda.kt")
public void testSamFromJava_lambda() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samFromJava_lambda.kt");
}
@Test
@TestMetadata("samFromJava_methodReference.kt")
public void testSamFromJava_methodReference() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samFromJava_methodReference.kt");
}
@Test
@TestMetadata("samLambda.kt")
public void testSamLambda() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samLambda.kt");
}
@Test
@TestMetadata("samMethodReference.kt")
public void testSamMethodReference() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samMethodReference.kt");
}
@Test
@TestMetadata("simpleCallWithNonMatchingArgs.kt")
public void testSimpleCallWithNonMatchingArgs() throws Exception {
@@ -766,6 +766,30 @@ public class FirStandaloneNormalAnalysisSourceModuleResolveCallTestGenerated ext
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samConstructorCall.kt");
}
@Test
@TestMetadata("samFromJava_lambda.kt")
public void testSamFromJava_lambda() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samFromJava_lambda.kt");
}
@Test
@TestMetadata("samFromJava_methodReference.kt")
public void testSamFromJava_methodReference() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samFromJava_methodReference.kt");
}
@Test
@TestMetadata("samLambda.kt")
public void testSamLambda() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samLambda.kt");
}
@Test
@TestMetadata("samMethodReference.kt")
public void testSamMethodReference() throws Exception {
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/samMethodReference.kt");
}
@Test
@TestMetadata("simpleCallWithNonMatchingArgs.kt")
public void testSimpleCallWithNonMatchingArgs() throws Exception {
@@ -0,0 +1,43 @@
KtSuccessCallInfo:
call = KtSimpleFunctionCall:
isImplicitInvoke = false
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
dispatchReceiver = KtExplicitReceiverValue:
expression = handler
isSafeNavigation = false
type = test.pkg.MyHandler
extensionReceiver = null
signature = KtFunctionLikeSignature:
receiverType = null
returnType = kotlin.Unit
symbol = test/pkg/MyHandler.stash(<dispatch receiver>: test.pkg.MyHandler, actor: test.pkg.MyInterface!, actors: (kotlin.collections.MutableList<test.pkg.MyInterface!>..kotlin.collections.List<test.pkg.MyInterface!>?)): kotlin.Unit
valueParameters = [
KtVariableLikeSignature:
name = actor
receiverType = null
returnType = test.pkg.MyInterface!
symbol = actor: test.pkg.MyInterface!
callableIdIfNonLocal = null,
KtVariableLikeSignature:
name = actors
receiverType = null
returnType = (kotlin.collections.MutableList<test.pkg.MyInterface!>..kotlin.collections.List<test.pkg.MyInterface!>?)
symbol = actors: (kotlin.collections.MutableList<test.pkg.MyInterface!>..kotlin.collections.List<test.pkg.MyInterface!>?)
callableIdIfNonLocal = null
]
callableIdIfNonLocal = test/pkg/MyHandler.stash
typeArgumentsMapping = {}
argumentMapping = {
lambda -> (KtVariableLikeSignature:
name = actor
receiverType = null
returnType = test.pkg.MyInterface!
symbol = actor: test.pkg.MyInterface!
callableIdIfNonLocal = null),
list -> (KtVariableLikeSignature:
name = actors
receiverType = null
returnType = (kotlin.collections.MutableList<test.pkg.MyInterface!>..kotlin.collections.List<test.pkg.MyInterface!>?)
symbol = actors: (kotlin.collections.MutableList<test.pkg.MyInterface!>..kotlin.collections.List<test.pkg.MyInterface!>?)
callableIdIfNonLocal = null)
}
@@ -0,0 +1,30 @@
// WITH_STDLIB
// FILE: MyInterface.java
package test.pkg;
interface MyInterface {
void act();
}
// FILE: MyHandler.java
package test.pkg;
import java.util.List;
public class MyHandler {
public void stash(MyInterface actor, List<MyInterface> actors) {
actors.add(actor);
}
}
// FILE: main.kt
package test.pkg
fun test(handler: MyHandler, list: List<MyInterface>) {
val lambda = { println("hello") }
<expr>handler.stash(lambda, list)</expr>
}
@@ -0,0 +1,43 @@
KtSuccessCallInfo:
call = KtSimpleFunctionCall:
isImplicitInvoke = false
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
dispatchReceiver = KtExplicitReceiverValue:
expression = handler
isSafeNavigation = false
type = test.pkg.MyHandler
extensionReceiver = null
signature = KtFunctionLikeSignature:
receiverType = null
returnType = kotlin.Unit
symbol = test/pkg/MyHandler.stash(<dispatch receiver>: test.pkg.MyHandler, actor: test.pkg.MyInterface!, actors: ft<kotlin.collections.MutableList<test.pkg.MyInterface!>, kotlin.collections.List<test.pkg.MyInterface!>?>): kotlin.Unit
valueParameters = [
KtVariableLikeSignature:
name = actor
receiverType = null
returnType = test.pkg.MyInterface!
symbol = actor: test.pkg.MyInterface!
callableIdIfNonLocal = null,
KtVariableLikeSignature:
name = actors
receiverType = null
returnType = ft<kotlin.collections.MutableList<test.pkg.MyInterface!>, kotlin.collections.List<test.pkg.MyInterface!>?>
symbol = actors: ft<kotlin.collections.MutableList<test.pkg.MyInterface!>, kotlin.collections.List<test.pkg.MyInterface!>?>
callableIdIfNonLocal = null
]
callableIdIfNonLocal = test/pkg/MyHandler.stash
typeArgumentsMapping = {}
argumentMapping = {
lambda -> (KtVariableLikeSignature:
name = actor
receiverType = null
returnType = test.pkg.MyInterface!
symbol = actor: test.pkg.MyInterface!
callableIdIfNonLocal = null),
list -> (KtVariableLikeSignature:
name = actors
receiverType = null
returnType = ft<kotlin.collections.MutableList<test.pkg.MyInterface!>, kotlin.collections.List<test.pkg.MyInterface!>?>
symbol = actors: ft<kotlin.collections.MutableList<test.pkg.MyInterface!>, kotlin.collections.List<test.pkg.MyInterface!>?>
callableIdIfNonLocal = null)
}
@@ -0,0 +1,33 @@
// WITH_STDLIB
// FILE: MyInterface.java
package test.pkg;
interface MyInterface {
void act();
}
// FILE: MyHandler.java
package test.pkg;
import java.util.List;
public class MyHandler {
public void act(MyInterface actor) {
if (actor != null) {
actor.act();
}
}
}
// FILE: main.kt
package test.pkg
fun callback() {}
fun test(handler: MyHandler, list: List<MyInterface>) {
<expr>handler.act(::callback)</expr>
}
@@ -0,0 +1,31 @@
KtSuccessCallInfo:
call = KtSimpleFunctionCall:
isImplicitInvoke = false
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
dispatchReceiver = KtExplicitReceiverValue:
expression = handler
isSafeNavigation = false
type = test.pkg.MyHandler
extensionReceiver = null
signature = KtFunctionLikeSignature:
receiverType = null
returnType = kotlin.Unit
symbol = test/pkg/MyHandler.act(<dispatch receiver>: test.pkg.MyHandler, actor: test.pkg.MyInterface!): kotlin.Unit
valueParameters = [
KtVariableLikeSignature:
name = actor
receiverType = null
returnType = test.pkg.MyInterface!
symbol = actor: test.pkg.MyInterface!
callableIdIfNonLocal = null
]
callableIdIfNonLocal = test/pkg/MyHandler.act
typeArgumentsMapping = {}
argumentMapping = {
::callback -> (KtVariableLikeSignature:
name = actor
receiverType = null
returnType = test.pkg.MyInterface!
symbol = actor: test.pkg.MyInterface!
callableIdIfNonLocal = null)
}
@@ -0,0 +1,13 @@
class Test {
fun interface Foo {
fun foo()
}
fun uiMethod() {}
fun test(foo: Foo) {}
fun testLambda() {
<expr>test { uiMethod() }</expr>
}
}
@@ -0,0 +1,54 @@
KtSuccessCallInfo:
call = KtSimpleFunctionCall:
isImplicitInvoke = false
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
dispatchReceiver = KtImplicitReceiverValue:
symbol = KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: Test
classKind: CLASS
companionObject: null
contextReceivers: []
isActual: false
isData: false
isExpect: false
isExternal: false
isFun: false
isInline: false
isInner: false
modality: FINAL
name: Test
origin: SOURCE
superTypes: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any
]
symbolKind: TOP_LEVEL
typeParameters: []
visibility: Public
type = Test
extensionReceiver = null
signature = KtFunctionLikeSignature:
receiverType = null
returnType = kotlin.Unit
symbol = /Test.test(<dispatch receiver>: Test, foo: Test.Foo): kotlin.Unit
valueParameters = [
KtVariableLikeSignature:
name = foo
receiverType = null
returnType = Test.Foo
symbol = foo: Test.Foo
callableIdIfNonLocal = null
]
callableIdIfNonLocal = /Test.test
typeArgumentsMapping = {}
argumentMapping = {
{ uiMethod() } -> (KtVariableLikeSignature:
name = foo
receiverType = null
returnType = Test.Foo
symbol = foo: Test.Foo
callableIdIfNonLocal = null)
}
@@ -0,0 +1,13 @@
class Test {
fun interface Foo {
fun foo()
}
fun uiMethod() {}
fun test(foo: Foo) {}
fun testMethodRef() {
<expr>test(this::uiMethod)</expr>
}
}
@@ -0,0 +1,54 @@
KtSuccessCallInfo:
call = KtSimpleFunctionCall:
isImplicitInvoke = false
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
dispatchReceiver = KtImplicitReceiverValue:
symbol = KtNamedClassOrObjectSymbol:
annotationsList: []
classIdIfNonLocal: Test
classKind: CLASS
companionObject: null
contextReceivers: []
isActual: false
isData: false
isExpect: false
isExternal: false
isFun: false
isInline: false
isInner: false
modality: FINAL
name: Test
origin: SOURCE
superTypes: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any
]
symbolKind: TOP_LEVEL
typeParameters: []
visibility: Public
type = Test
extensionReceiver = null
signature = KtFunctionLikeSignature:
receiverType = null
returnType = kotlin.Unit
symbol = /Test.test(<dispatch receiver>: Test, foo: Test.Foo): kotlin.Unit
valueParameters = [
KtVariableLikeSignature:
name = foo
receiverType = null
returnType = Test.Foo
symbol = foo: Test.Foo
callableIdIfNonLocal = null
]
callableIdIfNonLocal = /Test.test
typeArgumentsMapping = {}
argumentMapping = {
this::uiMethod -> (KtVariableLikeSignature:
name = foo
receiverType = null
returnType = Test.Foo
symbol = foo: Test.Foo
callableIdIfNonLocal = null)
}