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

Add rule to use runCatching instead of kotlin.runCatching #4448

Closed
gpeal opened this issue Jan 3, 2022 · 4 comments · Fixed by #4460
Closed

Add rule to use runCatching instead of kotlin.runCatching #4448

gpeal opened this issue Jan 3, 2022 · 4 comments · Fixed by #4460
Labels

Comments

@gpeal
Copy link

gpeal commented Jan 3, 2022

Expected Behavior

Per KTIJ-11561, Android Studio/IntelliJ will autocomplete runCatching to kotlin.runCatching which is inconsistent with other Kotlin APIs such as run which don't do that.

It would be great to have a rule that would enforce that it is used consistently as just runCatching across the codebase.

@gpeal gpeal added the feature label Jan 3, 2022
@BraisGabin
Copy link
Member

🤔 This should be work for ForbiddenMethodCall. But I'm not sure if it can handle something like that right now... I'm going to check.

@BraisGabin
Copy link
Member

BraisGabin commented Jan 4, 2022

As I was expecting ForbiddenMethodCall can't handle this case right now. For it both functions "are the same".

But the problem is bigger than that. Right now ForbiddenMethodCall doesn't suport:

  • functions with lambda parameters (if you want to specify the parameters)
  • functions with generics (if you want to specify the parameters)
  • extension functions

ForbiddenMethodCall needs to support those three to be able to handle this case. I have a draft for the first case.

@BraisGabin
Copy link
Member

🤔 the only way that I can think of handle extension functions with the current "function signature" is to treat the receiver type as the "first paramenter" of the function. This will not create any problem because the compiler doesn't allow you to define this two functions

fun String.hello()
fun hello(world: String)

because they have the same JVM signature. It is the only way I can think without adding a breaking change or deprecate the current function signature and create a new one.

In terms of UX it would be really hacky because it's difficult to think about: fun String.hello() as hello(kotlin.String) but it would work.

@gpeal
Copy link
Author

gpeal commented Jan 6, 2022

@BraisGabin That's great! I tried adding a separate ForbiddenMethodCall for an extension function yesterday and couldn't figure out why it wasn't working!

BraisGabin added a commit that referenced this issue Jan 25, 2022
BraisGabin added a commit that referenced this issue Jan 30, 2022
BraisGabin added a commit that referenced this issue Jan 31, 2022
BraisGabin added a commit that referenced this issue Mar 24, 2022
BraisGabin added a commit that referenced this issue Mar 31, 2022
* Match functions with generics

* Add test to ensure that #4448 is fixed
chao2zhang pushed a commit that referenced this issue Apr 8, 2022
* Match functions with generics

* Add test to ensure that #4448 is fixed
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 a pull request may close this issue.

2 participants