Skip to content
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

[JEP 488][Preview][Primitive Patterns] ECJ crashes compiling switch over void typed selector expression #3722

Merged
merged 3 commits into from
Feb 15, 2025

Conversation

stephan-herrmann
Copy link
Contributor

  • report error rather than crashing

Fixes #3369

Copy link
Contributor

@srikanth-sankaran srikanth-sankaran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No major issues. Three minor potential follow up comments.

" switch (foo()) {\n" +
" ^^^^^\n" +
"Expression must return a value\n" +
"----------\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Are both arms of the ternary identical now ? They appear so. Could they be collapsed together ?
  2. With the message Expression must return a value I feel the quality of the diagnostic actually degrades in this context. How about we change the message to Expression has no value - ("to switch on", "to synchronize with" etc left to be understood) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ad (1): your eagle eyes spotted correctly :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ad (2): I agree, that message is a bit odd.
"has no value" makes me think of "worthless" :)
Perhaps we can agree on "yields no value"?

Let me see if that change will cause a landslide in our tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me see if that change will cause a landslide in our tests.

Quite to the contrary. I can't find any tests covering the 2 pre-existing uses of this error message. I'll add a couple.

if (expressionType.id == TypeIds.T_void) {
upperScope.problemReporter().illegalVoidExpression(this.expression);
break checkType;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admittedly, this is even more corner case: What about 'V'oid methods ? should they be handled here too ? (Actually what can a Void method return other than null ? I have poor understanding here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed I can't see how switching over Void could ever do anything useful (you'd get NPE at best). Yet doing so would be legal code, in contrast to void.

void typed selector expression

+ report error rather than crashing

Fixes eclipse-jdt#3369
void typed selector expression

+ advoid secondary error
+ tentatively adjust tests from eclipse-jdt#2385

Fixes eclipse-jdt#3369
void typed selector expression

+ rephrase error message
+ add tests for pre-existing cases of that error

Fixes eclipse-jdt#3369
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.

2 participants