JEP 305 - Pattern Matching for instanceof (Preview)

Gavin Bierman gavin.bierman at
Wed Nov 27 13:26:03 UTC 2019

Hi Attila:

> One little comment on the "flow scoping" rules:
> As I can see `x = y` empties the binding sets (for both T and F).
> Is there a reason not to apply the same for them as if they were
> written as `(x && y) || (!x && !y)`. That is, the following:
> T: intersect(union(x.T, y.T), union(x.F, y.F))
> F: union(intersect(x.F, y.F), intersect(x.T, y.T))
> Obviously, this would apply for boolean x and y only,
> and the reverse for `x != y`

I appreciate the suggestion, thank you.

Unfortunately, there are a couple of problems. First, it is important to note that flow scoping applies only to pattern variables. So your suggestion as written doesn’t really apply. Even if it could, your observation also kills it - it would only “..apply for boolean x and y”. Scoping of variables happens way before typing - indeed, you can’t define typing without knowing scoping. 

We can construct a similar example to consider though; for example:

(e instanceof T x) == (f instanceof S y)

You define the True set as:

T: intersect(union(x.T, y.T), union(x.F, y.F))

So, in this case it’s:

intersect(union({x}, {y}), union({},{}))
= intersect({x,y}, {})
= {}

Similarly for the False set. In fact, I think this will always be the case. 

I would be very interested to hear any feedback you may have of using pattern matching in anger in the next few months. We really want to hear what works and, please!, what is awkward - that’s the purpose of ‘preview’ features.

Best wishes,

More information about the compiler-dev mailing list