-
-
Notifications
You must be signed in to change notification settings - Fork 76
fix: Reject decorated element types in arrayOf #2781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -551,6 +551,33 @@ describe('array', () => { | |
| - fn*:main(): Value [1, 2, 3] is not resolvable] | ||
| `); | ||
| }); | ||
|
|
||
| it('allows @location-decorated element types', () => { | ||
| const located = d.arrayOf(d.location(0, d.u32), 4); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the current implementation of vertexLayout, In This can be misleading, and maybe a better approach would be to make decorators single-purpose. We could find another way to pass shaderLocation to the vertex layout. What do you think? |
||
| expect(located.elementCount).toBe(4); | ||
| expectTypeOf(located).toEqualTypeOf<d.WgslArray<d.Decorated<d.U32, [d.Location<0>]>>>(); | ||
| }); | ||
|
|
||
| it('should allow calling arrayOf inside generic helpers', () => { | ||
| function arrayOf32<T extends d.AnyWgslData>(schema: T) { | ||
| return d.arrayOf(schema, 32); | ||
| } | ||
|
|
||
| arrayOf32(d.f32); | ||
| }); | ||
|
aleksanderkatan marked this conversation as resolved.
|
||
|
|
||
| it('throws when a non-location decorated element type is passed', () => { | ||
| expect(() => d.arrayOf(d.align(16, d.u32), 4)).toThrowErrorMatchingInlineSnapshot( | ||
| `[Error: Arrays cannot hold decorated types other than @location. Wrap it in a struct instead, e.g. d.arrayOf(d.struct({ value: d.align(16, d.u32) }), n).]`, | ||
| ); | ||
| expect(() => d.arrayOf(d.size(16, d.u32), 3)).toThrow(); | ||
| expect(() => d.arrayOf(d.location(0, d.align(16, d.u32)), 3)).toThrow(); | ||
|
Comment on lines
+569
to
+574
|
||
|
|
||
| const aligned = () => d.arrayOf(d.align(16, d.u32), 4); | ||
| expectTypeOf( | ||
| aligned, | ||
| ).returns.toEqualTypeOf<'Error: Arrays cannot hold decorated types other than @location. Wrap it in a struct instead, e.g. d.arrayOf(d.struct({ value: d.align(16, d.u32) }), n)'>(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('array.length', () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -861,7 +861,7 @@ describe('TgpuBuffer', () => { | |
| }); | ||
|
|
||
| it('should ignore decorated types when determining validity usage', ({ root }) => { | ||
| const validSchema = d.size(1024, d.arrayOf(d.align(16, d.u32), 32)); | ||
| const validSchema = d.size(1024, d.arrayOf(d.u32, 32)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change defeats the purpose of this test (either remove it or repurpose) |
||
|
|
||
| const buffer = root.createBuffer(validSchema); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter name
countin this error overload differs fromelementCountused in the two productive overloads below and in the JSDoc@param. Consider renaming toelementCountfor consistency.