----- Mail original ----- > De: "Gavin Bierman" <gavin.bier...@oracle.com> > À: "Remi Forax" <fo...@univ-mlv.fr> > Cc: "jan lahoda" <jan.lah...@oracle.com>, "amber-spec-experts" > <amber-spec-experts@openjdk.java.net> > Envoyé: Mardi 18 Février 2020 17:35:03 > Objet: Re: Pattern Matching for instanceof (Preview 2)
>> On 18 Feb 2020, at 15:04, fo...@univ-mlv.fr wrote: >> >> Hi Gavin, >> >> ----- Mail original ----- >>> De: "Gavin Bierman" <gavin.bier...@oracle.com> >>> À: "Remi Forax" <fo...@univ-mlv.fr> >>> Cc: "jan lahoda" <jan.lah...@oracle.com>, "amber-spec-experts" >>> <amber-spec-experts@openjdk.java.net> >>> Envoyé: Mardi 18 Février 2020 15:32:12 >>> Objet: Re: Pattern Matching for instanceof (Preview 2) >> >>> >>>> - must the identifier of a pattern argument be the same name as the >>>> corresponding record component ? >>>> To be coherent with the fact that constructors requires the same names. >>> >>> Absolutely not! Note this does mean that you can write confusing code: >>> >>> record Point(int x, int y) { } >>> >>> if (o instanceof Point(var y, var x)) { >>> … // y refers to x component, y refers to x component >>> } >>> >>> (I’ll get my coat…) >> >> yes, that's why i ask, it leads to very confusing code, some languages don't >> allow this kind of code, >> by example destructuring in JavaScript as a special syntax if you want to use >> different names. > > I appreciate this, but requiring you to use the record component name is not > very friendly if you have repeated nested patterns, e.g. > > if (o instanceof Line(Point(int x, int y), Point(int x, int y))) // Error two > occurrences of x and y! > { …} > > The only way around that would be to have explicit renaming operators, which > is > pretty ugly. yes, very good point. > > Gavin Rémi