[patterns-instanceof] Spec for next version of Patterns in instanceof JEP
Gavin Bierman
gavin.bierman at oracle.com
Thu Oct 8 09:18:45 UTC 2020
> On 5 Oct 2020, at 16:20, Brian Goetz <brian.goetz at oracle.com> wrote:
>
> 5.5. I think of `instanceof` as having two forms:
>
> o instanceof Type
> o instanceof Pattern
>
> This phrasing ("converted to the type indicated by the second operand") is consistent with the first, but I think needs a few more words to be consistent with the second? Every pattern has a "principal type" (making up a term); the principal type of a type pattern `T t` is `T`; the principal type of a deconstruction pattern `D(...)` is `D`. (The definition for other kinds of patterns like constant patterns or declared patterns are straightforward enough to define as needed.)
[The spec also thinks there are two forms of instanceof - see second line of 15.20.2!]
You don’t need to make up a term; it’s there already. In 14.30.1.1.:
The type of a type test pattern is the ReferenceType.
I use this notion of “type of a pattern” elsewhere. I tried to hedge the phrasing in 5.5 to spare myself mentioning both forms of instanceof, but perhaps it would just be clearer to do so.
Thanks.
Gavin
More information about the amber-spec-observers
mailing list