Whiley / RFCs

Request for Comment (RFC) proposals for substantial changes to the Whiley language.
3 stars 2 forks source link

Switch Statement #62

Open DavePearce opened 5 years ago

DavePearce commented 5 years ago

(see also #34)

An interesting dissection of switch statements in Java:

https://blog.joda.org/2019/11/java-switch-4-wrongs-dont-make-right.html

One idea is to incorporate a single switch statement which subsumes the proposed match statement. To do this, it requires:

  1. The switch covers all possible cases; or,
  2. The switch has a default statement.

For finite types (e.g. union types), covering all possible cases is feasible. For others, such as int it is not and therefore a default case will always be required.