-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Improve diagnostic quality for less accessible base type argument #80483
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
Improve diagnostic quality for less accessible base type argument #80483
Conversation
|
If wanted, i could also open a follow up pr, where i add seperate error messages for inaccessable type parameters and inaccessable parents of nested classes |
Co-authored-by: Jan Jones <[email protected]>
Co-authored-by: Jan Jones <[email protected]>
|
I am not sure why the pipelines are failing in spanish, but i suspect it as something to do with the failing tests on main? Is there a way for me to trigger the pipeline again, if i have no changes to push and not commits on main to merge into the branch? |
|
It seems doubtful the Spanish failure is related to this change. I'm kicking a rerun. Failure log |
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol_Bases.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Symbol/Symbols/Source/BaseClassTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol_Bases.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol_Bases.cs
Outdated
Show resolved
Hide resolved
|
@jjonescz Would you maybe have a quick moment to re-review? |
|
@jjonescz feel free to hit merge if you don't have any further feedback. |
| comp.VerifyDiagnostics( | ||
| // (3,14): error CS9335: Inconsistent accessibility: type 'A' is less accessible than class 'C' | ||
| // public class C : A.B { } | ||
| Diagnostic(ErrorCode.ERR_BadVisBaseType, "C").WithArguments("C", "A").WithLocation(3, 14)); |
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.
I'm wondering whether the message could be improved - since we squiggle the class C itself, the user might be confused where to search for the less accessible type (in nested types, in members, in base types, in attributes, ...) - i.e., should the message be something like this?
"Inconsistent accessibility: type A which appears in the base type is less accessible than class C"
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.
How would you like "Inconsistent accessibility: type A used in the base type is less accessible than class C"?
Not sure why, but that somehow sounds better to me (but that might be due to my slightly lacking english skills)
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.
I am just concerned about scalability, if we started reporting this same warning for member types and so on, would we want to have a bunch of different messages of this form? What if we just reported both errors, with the current message, in the case that an inner type of the base type is the cause of the bad accessibility?
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.
With "both errors" you mean like this?
error CS0060: Inconsistent accessibility: base type 'B<A>' is less accessible than class 'C'
error CS9335: Inconsistent accessibility: type 'A' is less accessible than class 'C'
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.
Yep. Let's see what others think and then we can come up with a decision.
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.
Reporting both errors works for me, thanks.
(The current state of the PR also works for me if others think that's better, this was not a blocking comment, just a thought about a possible improvement.)
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.
I am very much not a fan of reporting both errors; that just gets us back into the confusing situation that we started at. B<A> is not less accessible than C, and any error that states that it is is incorrect. I think the current form is perfectly reasonable.
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.
Is it something people would even be really confused about? IMHO most of the times when somebody is changing something and gets the error that A is less accessiable than C, he is probably aware, how C is related to A (as he must have done something that lets C inherit from A).
Most of the times i get the BadVisBaseClass is when i am having some internal stuff and accidently create a public subclass, so the common fix for this would be to correct the access modifier, which is also possible without knowing about the relation in detail.
So this effectively i feel like it only might be really confusing if somebody is unaware of the relation between C and A, while having a design flaw that expects an impossible inheritance. And even if that is the case, somebody who has seen Inconsistent accessibility: base class '{1}' is less accessible than class '{0}' a few times might not even recognize the different wording in Inconsistent accessibility: type '{1}' is less accessible than class '{0}' before instinctively knowing what went wrong (at least i would not expect myself to realize that the error is different).
Edit: Error could also occur if one of the access modifiers is changed, didn't think of that
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.
B<A>is not less accessible thanC
I don't agree with this statement. If this were true, it would mean that every place the compiler can currently complain about B<A> being insufficiently accessible in a signature, due to accessibility of A, is problematic. I don't believe that to be the case.
I think that when a compiler gives an error stating type '{1}' is less accessible than type '{0}', it is in reference to the accessibility domains concept in the standard, which states that accessibility domain of a constructed type is the intersection of the accessibility of the original definition and the type arguments.
That said, I am satisfied with the current behavior of the PR, and I think it's fine to move forward by resolving conflicts and merging with the current behavior.
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.
Conflicts are resolved, so it would be ready to merge?
|
Gonna fix the conflict as soon as the discussion about the exact errors emitted is resolved, want to avoid doing it more often than necessary |
|
Thanks @stbau04! |
| { | ||
| // Inconsistent accessibility: type '{1}' is less accessible than class '{0}' | ||
| var lessVisibleTypeLocation = lessVisibleType.GetFirstLocation(); | ||
| diagnostics.Add(ErrorCode.ERR_BadVisBaseType, baseTypeLocation, this, lessVisibleType); |
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.
Did you intend to use lessVisibleTypeLocation instead of baseTypeLocation in the diagnostics entry?
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.
iirc lessVisibleTypeLocation is the location of the type definition. So it would not be intended to be used instead of the baseTypeLocation, but the variable is not used anywhere so i guess the declaration can be removed #80823
Fixes: #40977