-
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
[21] JEP 443: Unnamed Patterns and Variables (Preview) #893
Comments
The relevant portion : If a declaration does not include an identifier, but instead includes the reserved keyword _ (underscore), then the entity cannot be referred to by name. The following kinds of entity may be declared using an underscore: A local variable, one of the following: A local variable declared by a local variable declaration statement in a block (14.4.2) A local variable declared by a for statement or a try-with-resources statement (14.14, 14.20.3) A local variable declared by a pattern (14.30.1) An exception parameter of an exception handler declared in a catch clause of a try statement (14.20) A formal parameter of a lambda expression (15.27.1) A local variable, exception parameter, or lambda parameter that is declared using an underscore is called an unnamed local variable, unnamed exception parameter, or unnamed lambda parameter, respectively. |
retargeting out of BETA_JAVA21 |
If no one else is currently working on this, I'm interested in taking a look at it. |
First things I've noticed:
This is likely the code to begin looking at. I suggest setting a breakpoint here. My initial reaction here is to impl as follows:
But of course some of this might need to be done earlier in the In the above check for This is as far as I've gotten thus far. |
Just as an update. @datho7561 & @robstryker have a basic idea of how the grammar works and were able to implement support for cases like : Also, it looks like there may be some work to do on the bytecode generation side since it's likely the unnamed variables shouldn't be added to any table tracking locals. |
I looked into what would be needed for bytecode generation. I experimented with generating bytecode using try {
throw new Exception();
} catch (Exception e1) {
try {
throw new Exception();
} catch (Exception e2) {
System.out.println("oh no");
}
}
This leads me to believe that nothing needs to changed about how the bytecode is generated. |
As an update for anyone following, we've implemented all cases of this. I think the case of "_" with no type at all is tricky in some places. We're preparing a PR that breaks things down as-per #1487 (comment) , as well as adding a bunch of tests for this. |
okay I pushed the code for the last case we weren't handling |
@datho7561 Wanted to check where you are wrt this implementation? I am adding a pr which I had for tests for this. Also adding myself as an additional assignee (hope you are fine) |
Thanks @rgrunber for linking the pr 1517 here.. will take a look |
TODO: Activate after eclipse-jdt/eclipse.jdt.core#893 is done. Signed-off-by: Alexander Kriegisch <[email protected]>
JDK 21 has been out for several months and Eclipse 2023-12 was announced to (fully?) support JDK 21. I am surprised that this was not part of the release. Is this going to be done anytime soon? I delayed the AspectJ release for JDK 21 for several months, waiting for JDT Core and ECJ to catch up with JDK 21. Now after the 2023-12 release, I thought I could also release AspectJ, but obviously I cannot or have to add a disclaimer about which preview features are still unsupported. This is no bashing, I know that probably you do not have much resources and understand. But I want to suggest to delay any JDK 22 features until all JDK 21 features are fully implemented. Or is the policy rather to always implement the final features for each JDK release, and preview features should are best effort, maybe done and maybe not? Please help me to understand this. Thank you. |
TODO: Activate after eclipse-jdt/eclipse.jdt.core#893 is done. Signed-off-by: Alexander Kriegisch <[email protected]>
Essentially the underscore _
ref: https://openjdk.org/jeps/443
"Summary
Enhance the Java language with unnamed patterns, which match a record component without stating the component's name or type, and unnamed variables, which can be initialized but not used. Both are denoted by an underscore character, _. This is a preview language feature."
JLS Draft changes at: https://cr.openjdk.org/~abimpoudis/unnamed/latest/
The text was updated successfully, but these errors were encountered: