-
Notifications
You must be signed in to change notification settings - Fork 139
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
Out of scope pattern variables suggested for completion #3600
Comments
I spent a lot of time today debugging this. Some pointers if someone wants to take a crack at it (I probably won't):
{
List myList;
int i;
{
}
String asdf;
} As a result, no |
Do you have a test case that shows a problem in compiler proper with pattern variables outliving the for loop's body incorrectly ?? Or being accessible before the for statement? There are cases where the pattern variables MUST outlive. Hence their addition to the parent scope. It could be that this is a completion specific defect. Please mark me for review on any changes made to core compiler for this. Thanks! |
Here is an example that must compile that shows the pattern variable introduced by the for's condition must outlive the for loop:
Can you browse through the uses of |
Okay that makes sense to me. However, in the case I presented, the pattern variables should not outlive the for loop, yet they are being added to the method scope anyways.
It is completion specific. The compiler outputs errors for trying to use the pattern variables when they are invalid, and allows them to be used after the loop in the snippet you mentioned. The changes I tried making to the scope are probably wrong.
This flag is not checked anywhere in the completion engine.
This is pretty confusing. Why is it done this way instead of adding the variable to the |
Well, that is Java for you. The variable is added to the BlockScope or MeehodScope it belongs to but that doesn't mean it is in scope - ie can be accessed. Pattern matching goes hand in hand with "flow scoping". A pattern binding variable is accessible only in regions of code where it is definitely assigned and not from point of declaration to the closing } that follows. So we flip the said flag at the right places to signal a pattern variable is out of scope. |
I tried using the flag to filter out the pattern variables, but I couldn't figure it out. It seemed to me like the flag was always set. My guess why this is happening is because, in the CompletionEngine, we get the resolved AST, and when the AST has finished resolving, all the pattern variables are marked out of the flow scope. Does this make sense? I looked into improving recovery for |
There are many problems in completion with respect to various constructs introduced in the last few years. A comprehensive overhaul is what is really called for - but allocating time may be a challenge. I have been busy overhauling core compiler implementation of several JEPs - this is nearly done with only Record classes in the queue for review/rewrite. After that hopefully I can look into this. |
eg. open completion at
|
and you will getjello
despite the fact that it's out of scopesame with the following case:
The text was updated successfully, but these errors were encountered: