----- Original Message ----- > From: "Brian Goetz" <[email protected]> > To: "Remi Forax" <[email protected]>, "amber-spec-experts" > <[email protected]> > Sent: Monday, October 24, 2022 7:06:15 PM > Subject: Re: Record pattern and enhanced for
>> Hi do not think we have yet discussed about using the record pattern in an >> enhanced for >> >> https://cr.openjdk.java.net/~gbierman/jep432%2b433/jep432+433-20221018/specs/patterns-switch-record-patterns-jls.html#jls-14.14.2 >> >> My first reaction when reading that part of the spec was, ok, cool, a bit >> weird >> to not piggyback it on pattern assignment but on the switch instead. > > It's not piggybacked on either. It's part of the Record Patterns JEP, > which lets you put record patterns in instanceof, switch, and foreach > contexts. (The semantics are indeed similar to pattern assignment, so > when that comes along, nothing new to learn.) The thing is that there are two ways to implement assignment + pattern, one is to consider that the pattern should be total on the type of the expression, the other is that it should be equivalent to a switch. The later does not work well because of the remainders (null + new subtypes due to separate compilation). I believe we have made the right call for switch to not force users to explicitly write the handling of the remainders but we can use a more strict approach for the assignment / inside an enhanced for. Rémi
