Skip to content

Conversation

@commonquail
Copy link
Contributor

@commonquail commonquail commented Feb 26, 2025

This PR nominally fixes #4847 but it is perhaps more illustrative than usable.

@commonquail commonquail force-pushed the identifiername-accept-unnamed branch 2 times, most recently from afc0184 to cc90fe1 Compare February 26, 2025 18:12

@Test
public void unnamedVariables() {
assume().that(Runtime.version().feature()).isAtLeast(22);
Copy link
Contributor Author

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

if (isStaticVariable(symbol) && isConformantStaticVariableName(name)) {
return true;
}
if (name.isEmpty()) {
Copy link
Contributor Author

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).

Copy link
Member

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 _) {}
Copy link
Contributor Author

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;

@graememorgan
Copy link
Member

Thanks for the fix!

@graememorgan graememorgan self-assigned this Feb 28, 2025
copybara-service bot pushed a commit that referenced this pull request Mar 7, 2025
This PR nominally fixes #4847 but it is perhaps more illustrative than usable.

Fixes #4848

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4848 from commonquail:identifiername-accept-unnamed cc90fe1
PiperOrigin-RevId: 733740757
copybara-service bot pushed a commit that referenced this pull request Mar 10, 2025
This PR nominally fixes #4847 but it is perhaps more illustrative than usable.

Fixes #4848

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4848 from commonquail:identifiername-accept-unnamed cc90fe1
PiperOrigin-RevId: 733740757
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IdentifierName: JEP 456 unnamed variable

2 participants