RFR: JDK-8231826: Implement javac changes for pattern matching for instanceof

Brian Goetz brian.goetz at oracle.com
Thu Oct 10 15:48:14 UTC 2019


>>> As far as I know, there is one (significant) open issue in the spec, and that is whether non-reifiable types should be allowed in "instanceof <type-test-pattern>". Currently (AFAIK), the spec does not allow non-reifiable types in the type test pattern in instanceof, and the javac implementation should be consistent with the spec. Should the spec change, the corresponding update to the javac code should have a very limited impact.

To be clear, do we treat `instanceof T` and `instanceof T t` differently, or do we disallow non-reifiable types in both places?  If the latter, I am fine to say that this is an enhancement that can come in later phases of PM.  The former is a little more worrisome, because I would expect users to be confused by an asymmetric treatment.


> * looking at the spec, it seems like both "instanceof T" and "instanceof T t" are cases of type test patterns.

This is true, though I suspect that ultimately we’ll have to refine the spec somewhat.  When we get to patterns in switch, or nested patterns, I think having `T` be a pattern will lead to amibiguties with constant patterns, and we’ll end up making the grammar a little more complicated in order to clean this up.  But, for now, the spec treats them the same, and there’s some good in that too.




More information about the compiler-dev mailing list