[switch] Status of implementation of switch expression
Jan Lahoda
jan.lahoda at oracle.com
Tue Feb 27 21:20:24 UTC 2018
On 27.2.2018 21:24, Brian Goetz wrote:
>
>> -enhanced exhaustiveness check for enums (if all existing constants
>> are covered, the "default" clause may be omitted, and javac will
>> generate it automatically. The automatically generated one will throw
>> an exception, although the form of the exception may need some
>> improvements). This is for switch expressions only.
>
> What is the form of the exception currently?
Only:
throw new IncompatibleClassChangeError();
>
>> -for switch statements and expressions over reference types, "case
>> null: <statements>" (or "case null -> <expression>" in case of switch
>> expression) may be used, which will be invoked when the reference is null
>> -multiple labels (for both switch statement and expression)
>
> Does the case null have to be first, or are there other ordering
> constraints? (For the current round, the only rule about placement of
case null must be first at this time, but is easy to change.
> case null we strictly need to follow in order to not make trouble later
> is that case null must precede the default, if present. But we may wish
> (or not) to make stricter requirements, for purposes of clarity.)
>
> Is the new translation (using indy) enabled by default?
Yes. Actually, while there's an non-indy translation of some of these
features, some of the features don't currently have a non-indy
translation (like switch over long, float, double, boolean). So some of
the new features only work with the indy translation.
I incline to dropping the changes to the non-indy translation (keeping
only the translations needed for the old --target values) and rely on
the indy translation for most of the new features.
Jan
>
>> Current (new) tests are in the following directories:
>
> If anyone wants to contribute, a place to start would be on the tests
> for the indy bootstraps that we are targeting. Bootstraps are in:
> http://hg.openjdk.java.net/amber/amber/file/2b837643a2d4/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java
>
>
> And the unit tests (testing the bootstraps directly, not testing the
> compiler support) are in:
> http://hg.openjdk.java.net/amber/amber/file/2b837643a2d4/test/jdk/java/lang/runtime/TestSwitchBootstrap.java
>
>
> The tests we have are currently quite basic, so we'd be happy for more
> coverage here.
>
>
More information about the amber-dev
mailing list