Don't crash when invoking signature help on an inaccessible item.#4157
Conversation
|
Tagging for review: @Pilchie @DustinCampbell @dpoeschl @davkean @jasonmalinowski @balajikris @basoundr @jmarolf @rchande |
|
WRT your question, I think the right approach is to show the inaccessible signature. The user will get an error after using it anyway. Maybe we'll add a code fix someday to change the accessibility of the member. That would make this a smooth experience. For VB, I think it's OK if the compiler has already removed the inaccessible members and doesn't consider them. However, if the IDE is removing the members, I think we should relax that. How do others feel? @Pilchie? |
|
I agree with @DustinCampbell -- let's show it. |
There was a problem hiding this comment.
So, what was the crash in the repro? It's not clear to me how this fixes a crash. Also, can throughSymbol.ContainingType be null? How does that impact this situation?
There was a problem hiding this comment.
The crash occurred on the next line, Contract.ThrowIfFalse() that was unhandled, and this makes the boolean true where it should be. As for ContainingType, the default to the method is null anyways and that simply means 'from this context', similar to the line above that doesn't specify the container, so it defaults to the class containing the method, B in this case.
There was a problem hiding this comment.
Got it. I didn't realize any of the methods on Contract compiled in release. Good to know.
There was a problem hiding this comment.
I'm still thinking about this - I understand that this fixes the issue, but doesn't feel quite right for some reason.
There was a problem hiding this comment.
From my perspective, we really shouldn't be failing fast and crashing the user's machine within signature help providers. In my observation, signature help can get all sorts of mangled trees and the providers should be somewhat resilient and just return null when things bind in ways we don't expect. I'd prefer a debug-only assert over crashing VS and causing the user to lose their unsaved changes.
Just my 2 cents.
There was a problem hiding this comment.
I agree with the not crashing bit. One of my concerns is the existence of this IncludeStatic and IncludeInstance code - we have a bunch of it in Completion that @rchande was just touching due to late regressions in VB. Should we share that code?
There was a problem hiding this comment.
The code here is basically asking the same two questions: "could this name have bound to a type?" and "could this name have bound to a non-type?". I could see us adding the extension methods ISymbol.CouldHaveBoundAsType(position, name) and ISymbol.CouldHaveBoundAsSomethingOtherThanAType(position, name) and using them in at least the 3 places that do this check.
|
retest this please |
4bb86d6 to
da94be6
Compare
|
Pinging for additional feedback/signoff given that we had a hallway discussion yesterday that this fix should just be targeted at fixing the crash and not about making signature help crash-proof. |
There was a problem hiding this comment.
Nitpick: name the test for what it's testing about inaccessible items, since without looking I could imagine this would either assert they are there or they aren't there.
|
👍 |
…ider the left expression explicitly, not just by name
8a0e1f8 to
19a1358
Compare
Don't crash when invoking signature help on an inaccessible item.
Fixes #4144.
As reported by a customer, when attempting to show signature help on an inaccessible item can cause a crash. The fix is: when checking if we're looking for instance members, also consider the containing type of the invocation expression, not just if it's name is visible.
Question for reviewers:
Consider the following code (taken from the unit test):
There is no crash in VB, but the
argssymbol also doesn't bind to begin with, like it does in C#. Given this scenario it can either be argued that when the user typedargsthey knew exactly what they were doing and they intend to update the definition ofargsto bepublicorprotected, or, they were unaware of the private field and they might be surprised by the completion/sig-help sessions that follow the dot. Thoughts?As it stands now,
Add(int item)appears in the completion list after typing the dot in C#, but nothing appears in VB.Edit
After digging in a bit, VB does show the appropriate completion items, but I wasn't originally seeing that due to some unnoticed changes on my box.