Skip to content

fix: Simultaneous implicit casts and derefs #2519

@aleksanderkatan

Description

@aleksanderkatan

This code silently produces invalid WGSL.

  it('disallows implicit casts in d.ref', () => {
    const modify = tgpu.fn([d.ptrFn(d.u32)])((numRef) => {
      'use gpu';
      numRef.$ += 1;
    });

    const main = tgpu.fn([])(() => {
      'use gpu';
      const num = d.f32();
      modify(d.ref(num));
    });

    expect(tgpu.resolve([main])).toMatchInlineSnapshot(`
      "fn modify(numRef: ptr<function, u32>) {
        (*numRef) += 1u;
      }

      fn main() {
        const num = 0f;
        modify((&num));
      }"
    `);
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions