Named record pattern

Tagir Valeev amaembo at gmail.com
Tue May 31 13:42:47 UTC 2022


Hello!

On Mon, May 30, 2022 at 6:54 PM Brian Goetz <brian.goetz at oracle.com> wrote:
> I must admit to being very surprised that you can do this at all!  I
> don't recall discussion on this, and had you asked me, I would have said
> that `final` has no place in type-test patterns.  Yet, I just tried it
> with jshell and it does work as you say.  I am surprised.
>
> Can someone recall any discussion over this?  (Surely now someone will
> point me to where I agreed to this.)
>
> Worse, it even works in switch labels!  This is definitely not what I
> had in mind.  Did this happen because we reused the local variable
> production for type patterns?  Since switch patterns are about to exit
> preview, I think we need to fix this ASAP, before switch exits preview.

Erm... I actually thought that it was your idea to allow the 'final'
modifier on patterns. This change was introduced in Java 16 (when
patterns for instanceof were finalized). Here's the initial e-mail
from you (item 2):
https://mail.openjdk.java.net/pipermail/amber-spec-experts/2020-August/002433.html
There was also subsequent discussion but eventually nobody was really
against and this was finalized.

>
> > It looks like,
> > "obj instanceof final Point(int x, int y) p" syntax is not allowed
> > which brings some asymmetry
> >   - In the first case I can use LOCAL_VARIABLE annotations like 'obj
>
> This very question is why I would not have encouraged us to try to do
> this for type test patterns at all!
>
> > instanceof @Cartesian Point p'. It looks like I cannot do the same in
> > the second case, which is another asymmetry.
>
> We definitely intended to not allow declaration annotations.

But they are allowed for type test patterns, since Java 16.

> As to
> type-use annotations; well, that's a different problem, and I'm not
> quite sure what to do.  For sure, we are not going to amend the
> XxxTypeAnnotations attributes to reify the position of these
> annotations.  If we allow them and make them available only to
> annotations processors only, that's another kind of asymmetry, that
> someone else will complain about.
>
> > So if I want to upgrade the type test pattern on a record type to a
> > record pattern to match components, I need to give up some features
> > like finality and annotations. Is this intended?
>
> It was not really intended that you got those features in the first place.
>
>


More information about the amber-spec-experts mailing list