Sections 18.2.4.3 VALUES and 18.2.4.4 SELECT Expressions look to be in the wrong order.
The SELECT clause is composite and, for example, any the aggregation steps should be before joining with VALUES as should assignments. Only solution modifiers should apply. (Ideally, apply projection, then VALUES then the other solution modifiers.)
P := Join(P, ToMultiSet(data))
would become
X := Join(X, ToMultiSet(data))
when 18.2.4.3 VALUES is moved after 18.2.4.4 SELECT Expressions.