Diamond in type patterns?

forax at univ-mlv.fr forax at univ-mlv.fr
Thu Jan 7 21:16:50 UTC 2021


----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>, "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Lundi 4 Janvier 2021 20:42:34
> Objet: Re: Diamond in type patterns?

>> If you use pattern matching without inference, the mix between parenthesis and
>> angle brackets rapidly becomes unreadable, so for a type pattern inside a
>> switch, I think that even the diamond syntax is too much.
>>
>> So IMO we should use the same inference as the method reference for the type
>> pattern in a switch.
> 
> That ship may unfortunately have sailed.  Currently `Foo f` declares the
> type of `f` as "raw Foo", and feature is finalized in 16.  (We had a
> long time to notice this.)

The other solution is to have the instanceof type pattern and the switch case pattern to have different inference rules.
That seems stupid but while we have tried to kept instanceof + type pattern to be equivalent to instanceof + cast + bind, we are more free with the switch case + type pattern.

And for the record, all the patterns should be released at the same time and not bit by bit like you are trying to because we will discover more discrepancies like this down the line.
We can still now decide to keep the instanceof + type pattern has a preview feature, so ensure that all patterns are coherent altogether.

Rémi


More information about the amber-spec-experts mailing list