Skip to content
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

KE2: Extract String.plus and String?.plus calls #17752

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

tamasvajk
Copy link
Contributor

No description provided.

@tamasvajk tamasvajk marked this pull request as ready for review October 14, 2024 13:58
@tamasvajk tamasvajk requested a review from a team as a code owner October 14, 2024 13:58
symbol.callableId?.callableName?.asString() == functionName
return isFunctionMatchingNames(
symbol,
CallableId(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it would be better to avoid constructing anything from kotlinc if possible, especially if we are aiming to use concurrency, as then we don't have to worry about what side-effects etc there might be. Here I think we can just as easily destruct the CallableId at the other end, as construct it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CallableId and ClassId are tuples of 3 and 2 names. Should we introduce custom data classes instead of reusing the kotlin compiler types? I don't think we'd want to pass 3 + 2 String args instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just been looking at how we might handle this problem in general; I'm more interested in cases where we want to extract e.g. a generated function, for which the analysis API doesn't give us the AST and we have to fabricate it. I was hoping that we could have our own CodeQlFunction interface, and have it be implemented by KtFunction using something like delegates. However, it looks like that isn't possible; there have long been discussions and proposals (e.g. https://youtrack.jetbrains.com/issue/KT-505, Kotlin/KEEP#87) but no implementation yet.

Perhaps CallableId and ClassId are simple enough that we should just reuse them? Or at least, do that for now until we come to something like the generated-function problem?

return false

if (!isExtension)
return true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused what's going on here. Should this be if (!isExtension && receiverType == null)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworked this a bit in an extra commit. My goal was to only use the last two parameters if isExtension==true.

isExtension: Boolean = false,
nullability: KaTypeNullability = KaTypeNullability.UNKNOWN,
extensionReceiverClassName: ClassId? = null
): Boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if this would read more clearly as an extension, so you'd have symbol.isFunctionMatchingNames(name, isExtension, nullability, extensionReceiverClassName)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed an extra commit that changed the functions to extensions.

@tamasvajk tamasvajk merged commit 9a4cd21 into github:ke2 Oct 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants