-
Notifications
You must be signed in to change notification settings - Fork 751
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
IdentifierName: support JDK 22 unnamed variables #4848
base: master
Are you sure you want to change the base?
IdentifierName: support JDK 22 unnamed variables #4848
Conversation
afc0184
to
cc90fe1
Compare
|
||
@Test | ||
public void unnamedVariables() { | ||
assume().that(Runtime.version().feature()).isAtLeast(22); |
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.
Or 21 and --enable-preview --release n
References: google#4847 References: https://openjdk.org/jeps/456
@@ -278,6 +278,9 @@ private static boolean isConformant(Symbol symbol, String name) { | |||
if (isStaticVariable(symbol) && isConformantStaticVariableName(name)) { | |||
return true; | |||
} | |||
if (name.isEmpty()) { |
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.
isConformant
is also called for methods. That seems ok; javac
does not accept an absent method name and rejects the meta-name _
with
/Test.java:5: error: underscore not allowed here
void _() {
and if, improbably, that ever did change, presumably an unnamed method should be treated no differently from an unnamed variable.
A more difficult question is whether something without a name can "conform" to a naming scheme. It seems more like asking the question in the first place is nonsensical. So perhaps this check should be at a higher level inside the checker, and perhaps it should be more explicitly isUnnamed(name)
.
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.
A more difficult question is whether something without a name can "conform" to a naming scheme.
I think most definitions you'd give of, say, lowerCamelCase would pass for the empty string, so I think the answer here is just "yes".
Function<String, String> f = _ -> "bar"; | ||
String _ = f.apply("foo"); | ||
} | ||
catch (Exception _) {} |
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.
Possibly all these are excessive compared to just
int _ = 1;
Thanks for the fix! |
This PR nominally fixes #4847 but it is perhaps more illustrative than usable.