Skip to content

Conversation

@aleksanderkatan
Copy link
Contributor

@aleksanderkatan aleksanderkatan commented Dec 15, 2025

wgslGenerator.ts

// Logical/Binary/Assignment Expression
const [exprType, lhs, op, rhs] = expression;
const lhsExpr = this.expression(lhs);

After this, the lhsExpression already is a constant snippet, so I decided to just update the error message for assigning to a constant.

Case 1:

let a = undefined;
const f = tgpu.fn([])(() => {
  a = 2;
});

as was before, an error Identifier a not found is thrown.

Case 2:

let a = 0;
const f = tgpu.fn([])(() => {
  a = 2;
});

Now the error message is '${lhsStr} = ${rhsStr}' is invalid, because ${lhsStr} is a constant. This error may also occur when assigning to a value defined outside of a TypeGPU function's scope.

@aleksanderkatan aleksanderkatan linked an issue Dec 15, 2025 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Dec 15, 2025

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@64d0e2a8cb3c37cf36297f604c9fc40775d24cda
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@64d0e2a8cb3c37cf36297f604c9fc40775d24cda
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@64d0e2a8cb3c37cf36297f604c9fc40775d24cda

benchmark
view benchmark

commit
view commit

@cieplypolar
Copy link
Collaborator

cieplypolar commented Dec 18, 2025

I am not sure if this is proper way to detect 'assignment to variables defined outside TGSL'. We are adding support for 'for ... of ...' loop, so tinyest will change. Maybe you'll find a better place for that in tinyest parsers?

EDIT: Nevermind, too much work for 1 error. LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Assignment to values from outer scope

3 participants