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

Evemose duke at openjdk.org
Sun Jun 23 21:04:41 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 yields value found".
> 
> If anyone have ideas on how to furthernore improve this error message, please feel free to share.

Evemose has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:

 - Merge branch 'openjdk:master' into improved-switch-expr-error
 - fix typo
 - init

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/19837/files
  - new: https://git.openjdk.org/jdk/pull/19837/files/27b3c09b..b8a355c6

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=19837&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=19837&range=01-02

  Stats: 96939 lines in 2152 files changed: 60969 ins; 25580 del; 10390 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