2.1.7. Pattern Variable Assignment

[Tip]Description

A pattern variable assignment is part of a pattern body. It defines the equality of two locally visible variable.

[Important]Syntax
PatternVariableAssignmentAST ::= PatternVariableRefAST = PatternVariableRefAST
[Note]Semantics

By default, two pattern variables are bound to different model elements according to the injective pattern matching principle. By pattern variable assignment, two pattern variables are declared to be equal, i.e. to store (share) the same model element.

The effect of a pattern variable assignment $X = Y $depends on the bindings of pattern variables as follows:

  • If both X and Y are bound (input) pattern variables, or both of them are free variables, then the pattern matcher treats X = Y as a constraint. Furthermore, it obviously removes injectivity checks for the pair X and Y.

  • If exactly one of pattern variables X and Y are free (e.g. let it be X), then the value of the bound variable Y is assigned to the free variable X.

[Caution]Constraints

At least one of the variables in the assignment have to appear in the pattern body either as locally defined body element or in a (positive) pattern composition, otherwise a compile-time error is generated.

Defined In:  pattern body