inject_assignment_coercions

Function inject_assignment_coercions 

Source
pub fn inject_assignment_coercions(src: &str, table: &SymbolTable) -> String
Expand description

Walk the source for <bare_ident> <op>= <expr>; statements (where <op> is empty for plain assignment or one of + - * / for compound assignment). When the inferred type of <expr> doesn’t match the declared type of <bare_ident>, inject the HLSL implicit conversion (broadcast or truncate).

This is the assignment-statement analogue of inject_truncations, which handles var X: T = ... declarations. The dominant motivating case is ret += tex3D(...)*0.5; where ret is vec3 in the wrapper preamble and the tex3D fallback returns vec4 — WGSL refuses with InvalidBinaryOperandTypes.

Conservative scope:

  • LHS must be a bare identifier (no swizzle, no array index).
  • LHS must resolve to a known vec or scalar type in table.
  • RHS must infer to a known type that differs from LHS.
  • Compound *= / /= only fire when RHS is scalar→vec (broadcast) or larger vec→smaller (truncate) — leaving matrix-mul ambiguity well alone.