-
-
Notifications
You must be signed in to change notification settings - Fork 777
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
NestedClassesVisibility(False negative): Nested class doesn't inherit visibility from parent #1930
Comments
Sorry for handling this issue so late. This fell completely under our radar.
Could you please provide a source for this statement? Please also keep in mind that there is a reason for having this rule in the |
If I have following code in internal class A {
class B
} and try to use it in fun main() {
A.B()
} the compiler won't let you, so the visibility is inherited. So this rule ensures that something like class A {
internal class B
} is used. |
The main issue with this rule is that it forces the use of an additional unnecessary modifier.
is non-compliant with the current implementation of the rule. The visibility of class B is already
which is pretty cumbersome. Also, because the inner classes inherit their visibility from the parent class, inner classes cannot have visibility greater than their parent class. So, afaik -
|
Thanks for the explanation, now I got your point. |
That would work for me. :) |
Is this rule even useful?
What I understand from that is that any inner class should be But even with the So, in my opinion we should:
|
* Don't flag inherited visibility in NestedClassesVisibility The rule had an issue that it forced the use of an additional unnecessary modifier. However, the visibility of nested classes is inherited from the parent class. These nested classes can't have a higher visibility than their parent. The following example outlines the issue. internal class A1 { // non-compliant class B } internal class A2 { // compliant internal class B } Closes #1930 * Add test case for nested internal class * Generate docs for NestedClassesVisibility rule * Add test case for nested public enum
From the comment,
NonCompliant
Compliant
In actuality, both should be Non Compliant.
This is because both are equivalent as the nested class inherits its visibility from its parent class.
So effectively, the
public
class in the initial example is alsointernal
.The way it's written, just marking an already "internal" class "internal" makes the violation go away.
The text was updated successfully, but these errors were encountered: