RFR: 8334722: Error emitted when switch expression does not yield any value lacks reasoning

Evemose duke at openjdk.org
Fri Jun 21 17:47:18 UTC 2024


Please review this trivial enhancement to informativity of error emiited when switch expression does not yield value in any branch lacks reasoning.

Issue body: 
Currently, when switch expression does not yield any value, compiler emits following error: "switch expression does not have any result expressions". While this gives information on how to solve the issue, the exact reason of this error stays unclear, expecially because switch *statements* do not have same requirement. Recently, there even were question about this in one of jdk mailing lists.

The source of issue becomes obvious if we look where this error is reported: it is emmited in Attr class when javac is unable to assign type to switch expression. Therefore, I propose to change the emitted error text to following: "Unable to determine switch expression type: no branch that yield value found".

If anyone have ideas on how to furthernore improve this error message, please feel free to share.

-------------

Commit messages:
 - init

Changes: https://git.openjdk.org/jdk/pull/19837/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=19837&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8334722
  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/19837.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19837/head:pull/19837

PR: https://git.openjdk.org/jdk/pull/19837


More information about the compiler-dev mailing list