-
Notifications
You must be signed in to change notification settings - Fork 353
Description
The grammar change for assignments, from #2265, is unintentionally too restrictive, and leads to ambiguous type-check.
lhs_expression :
| ( star | and ) * core_lhs_expression component_or_swizzle_specifier ?
core_lhs_expression :
| ident
Problem 1: m[0][1] = 1; should parse, but the grammar says it shouldn't. There is no way to chain component_or_swizzle_specifiers.
Problem 2 is in the structure of lhs_expression itself. It doesn't say whether we're forming expressions left-associatively or right-associatively:
- if left-associatively, then we're binding the & and * operators to the core_lhs_expression first, and then applying the effect of the component_or_swizzle_specifier
- if right-associatively, then we're applying the component_or_swizzle_specifier to the core_lhs_expression first, and then applying indirections and address-ofs.
- This is a material difference because component_or_swizzle_specifier only applies to plain or reference types, not to pointer types. (Since Add pointer-chaining expressions: ptr.field and ptr[i] #1580 is rejected for v1);
Example:
fn foo() {
var m: mat2x2<f32>;
let p = &m;
*p[0] = m[1];
} Is that LHS parsed and type checked as (*p)[0] which will then work, or is it parsed as *(p[0]) which will fail type-check due to #1580 not being supported.
edit: Problem 1 doesn't exist. I was missed the recursive nature of component_or_swizzle_specifier