-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
[MemberNameEqualsClassName] Support factory exemption for generic classes #3595
[MemberNameEqualsClassName] Support factory exemption for generic classes #3595
Conversation
There may be a better way to do this, as I don't fully understand the kotlin compiler psi APIs, but this works for the test case included and falls back to the previous implementation for other cases. |
Codecov Report
@@ Coverage Diff @@
## main #3595 +/- ##
============================================
- Coverage 77.53% 77.53% -0.01%
- Complexity 2835 2837 +2
============================================
Files 464 464
Lines 8779 8783 +4
Branches 1720 1721 +1
============================================
+ Hits 6807 6810 +3
Misses 1046 1046
- Partials 926 927 +1
Continue to review full report at Codecov.
|
val code = """ | ||
data class GenericClass<T>(val wrapped: T) { | ||
companion object { | ||
fun <T> genericClass(wrapped: T): GenericClass<T> { |
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.
In this test is not clear if the problem was the generic in the class or the generic in the function. Could you simplify it? Or, if they are both, create two tests.
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.
Added a non-generic factory function to the test, does that help?
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.
Which is the problem exactly this code:
data class GenericClass(val wrapped: Any) {
companion object {
fun <T> genericClass(wrapped: T): GenericClass<T> {
return GenericClass(wrapped)
}
}
}
or this:
data class GenericClass<T>(val wrapped: T) {
companion object {
fun genericClass(wrapped: Any): GenericClass<Any> {
return GenericClass(wrapped)
}
}
}
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.
the top one is closer to real world usage, but i suppose the bottom one is the minimal example? both fail without the change and pass with it, fwiw.
Compare the referenced type name instead of the fully qualified generic type name when possible. Fixes detekt#3591
36bdf01
to
3017ef2
Compare
Compare the referenced type name instead of the fully
qualified generic type name when possible.
Fixes #3591