@@ -46,7 +46,7 @@ describe('tgpu.const', () => {
4646 ` ) ;
4747 } ) ;
4848
49- it ( 'cannot be passed directly to shellless functions' , ( ) => {
49+ it ( 'can be passed directly to shellless functions (as arguments cannot be mutated anyway) ' , ( ) => {
5050 const fn1 = ( v : d . v3f ) => {
5151 'use gpu' ;
5252 return v . x * v . y * v . z ;
@@ -58,11 +58,16 @@ describe('tgpu.const', () => {
5858 return fn1 ( foo . $ ) ;
5959 } ;
6060
61- expect ( ( ) => tgpu . resolve ( [ fn2 ] ) ) . toThrowErrorMatchingInlineSnapshot ( `
62- [Error: Resolution of the following tree failed:
63- - <root>
64- - fn*:fn2
65- - fn*:fn2(): Cannot pass constant references as function arguments. Explicitly copy them by wrapping them in a schema: 'vec3f(...)']
61+ expect ( tgpu . resolve ( [ fn2 ] ) ) . toMatchInlineSnapshot ( `
62+ "fn fn1(v: vec3f) -> f32 {
63+ return ((v.x * v.y) * v.z);
64+ }
65+
66+ const foo: vec3f = vec3f(1, 2, 3);
67+
68+ fn fn2() -> f32 {
69+ return fn1(foo);
70+ }"
6671 ` ) ;
6772 } ) ;
6873
@@ -116,49 +121,4 @@ describe('tgpu.const', () => {
116121 }"
117122 ` ) ;
118123 } ) ;
119-
120- it ( 'cannot be passed directly to shellless functions' , ( ) => {
121- const fn1 = ( v : d . v3f ) => {
122- 'use gpu' ;
123- return v . x * v . y * v . z ;
124- } ;
125-
126- const foo = tgpu . const ( d . vec3f , d . vec3f ( 1 , 2 , 3 ) ) ;
127- const fn2 = ( ) => {
128- 'use gpu' ;
129- return fn1 ( foo . $ ) ;
130- } ;
131-
132- expect ( ( ) => tgpu . resolve ( [ fn2 ] ) ) . toThrowErrorMatchingInlineSnapshot ( `
133- [Error: Resolution of the following tree failed:
134- - <root>
135- - fn*:fn2
136- - fn*:fn2(): Cannot pass constant references as function arguments. Explicitly copy them by wrapping them in a schema: 'vec3f(...)']
137- ` ) ;
138- } ) ;
139-
140- it ( 'cannot be mutated' , ( ) => {
141- const boid = tgpu . const ( Boid , {
142- pos : d . vec3f ( 1 , 2 , 3 ) ,
143- vel : d . vec3u ( 4 , 5 , 6 ) ,
144- } ) ;
145-
146- const fn = ( ) => {
147- 'use gpu' ;
148- // @ts -expect-error: Cannot assign to read-only property
149- boid . $ . pos = d . vec3f ( 0 , 0 , 0 ) ;
150- } ;
151-
152- expect ( ( ) => tgpu . resolve ( [ fn ] ) ) . toThrowErrorMatchingInlineSnapshot ( `
153- [Error: Resolution of the following tree failed:
154- - <root>
155- - fn*:fn
156- - fn*:fn(): 'boid.pos = vec3f()' is invalid, because boid.pos is a constant. This error may also occur when assigning to a value defined outside of a TypeGPU function's scope.]
157- ` ) ;
158-
159- // Since we freeze the object, we cannot mutate when running the function in JS either
160- expect ( ( ) => fn ( ) ) . toThrowErrorMatchingInlineSnapshot (
161- `[TypeError: Cannot assign to read only property 'pos' of object '#<Object>']` ,
162- ) ;
163- } ) ;
164124} ) ;
0 commit comments