[code-reflection] RFR: Update the model of pattern matching when pattern variable identifier is underscore [v2]

Paul Sandoz psandoz at openjdk.org
Tue Sep 10 20:03:33 UTC 2024


On Tue, 10 Sep 2024 15:40:36 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> Type pattern can't use var
>
> In the JLS there is the `MatchAllPattern` in the grammar. I think it would be clearer to model this explicitly as a distinct pattern operation e.g. a `MatchAllPatternOp`, rather than model as a `BindingPatternOp` with a special name. For `_` there will be no binding to a pattern variable on a successful match (which is always successful and never partial) as there is no variable to bind to.
> 
> Separately, we probably should rename `BindingPatternOp` to `TypePatternOp` to be consistent with the names in the JLS.
> 
> @mcimadamore the current way the modeling works for `BindingPatternOp` (modelling a `TypePattern`) is the `Var` modeling the pattern variable only comes into existence when lowered, and it may be in a broader scope than in the source (since we currently don't do flow analysis and represent that in the model).

I realized i was confusing use of `_` in a type pattern `o instanceof T _` and a record pattern `R(_)`. The former is a type pattern but it has no binding of its match result. The name `BindingPatternOp` follows the naming in the compiler (`JCBindingPattern` and `BindingPatternTree`) ,which is confusing when there is no binding. We should rename `BindingPatternOp` to `TypePatternOp` and then we make it clearer whether there is a binding to a variable or not. (Mourad I and discussed this off-line.)

-------------

PR Review Comment: https://git.openjdk.org/babylon/pull/227#discussion_r1752654034


More information about the babylon-dev mailing list