-
Notifications
You must be signed in to change notification settings - Fork 381
[kotlin2cpg] Add support for KtCallableReferenceExpression #5775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| |""".stripMargin) | ||
|
|
||
| inside(cpg.call.name("filter").argument.l) { case List(receiver, methodRef: MethodRef) => | ||
| methodRef.methodFullName shouldBe "<unresolvedNamespace>.isOdd:boolean(int)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does isOdd really have <unresolvedNamespace>.isOdd:boolean(int) as method full name? If yes that is already a problem, if not the methodRef should use the same method full name as the referenced method.
| val methodRef = methodRefs.head | ||
|
|
||
| // The exact type will depend on Kotlin stdlib resolution | ||
| methodRef.methodFullName should include("forEach") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forEach is not a full name. I would have expected something like e.g. kotlin.collection.forEach(...).
| inside(cpg.call.name("doNothing").argument.l) { case List(thisArg: Identifier, methodRef: MethodRef) => | ||
| thisArg.name shouldBe "this" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing for this argument does not really belong to the thing we want to check here. Please remove it.
| thisArg.name shouldBe "this" | ||
|
|
||
| methodRef.methodFullName shouldBe "com.test.Bar.bar:void(int)" | ||
| methodRef.typeFullName shouldBe "com.test.Bar" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. You seem to have looked at Javasrc2cpg, but that is/was sadly not a good example and Johannes is fixing it there as we speak.
You basically have to create a new synthetic TYPE_DECL and a corresponding TYPE which is then referenced here in typeFullName. This new TYPE_DECL then needs bindings that reflect the implemented interface.
I suggest you and @johannescoetzee talk tomorrow so that he can tell you the details.
One pointer where most of this is already implemented and tested are the Lambda function tests in Javasrc2cpg here
No description provided.