These rules seem fine too me. 

Because you ask, the other solution is to introduce a raw type conversion of U, 
so the first bullet point can be T as to be cast convertible to raw(U). 

regards, 
Rémi 

> De: "Gavin Bierman" <[email protected]>
> À: "amber-spec-experts" <[email protected]>
> Envoyé: Vendredi 3 Novembre 2017 11:46:40
> Objet: Patterns design question: Generics

> Generics

> A related problem to the issue of null and pattern matching is dealing with
> patterns mentioning generic types. Currently, it is forbidden to use 
> instanceof
> with a non-reifiable type. However, we suspect that Java programmers would
> expect the following to work:
> ArrayList<Integer> al = ...
> if (al matches List<Integer> li) {
>     ...
> }

> Whereas perhaps it is to be expected that the following is suspect
> Object o = ...
> if (o matches List<Integer> li) {
>     // How could we perform this test?
> }

> The type restatement distinction that we introduced in the previous email for
> dealing with null provides a way forward.

> More formally, given an expression e matches U u where e has type T :

>    * If T is assignment convertible to U then this is a type restatement 
> pattern
>     match, and is allowed regardless of the type U (even if it is 
> non-reifiable).
>    * If T is cast convertible to U , but not assignment convertible, then we 
> emit a
>     warning/error as per the cast conversion rules.

> Do we have any other design options here?

Reply via email to