| <!DOCTYPE html> |
| <html> |
| <meta charset=utf-8> |
| <meta name="timeout" content="long"> |
| <title>Test structs.</title> |
| <script src="js/test-harness.js"></script> |
| <script src="../js/webgpu-functions.js"></script> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <script> |
| const whlslTests = {}; |
| |
| whlslTests.setterWithMatchedType = async () => |
| { |
| await checkFail(` |
| int operator.foo(int) |
| { |
| return 5; |
| } |
| int operator.foo=(int, int) |
| { |
| return 543; |
| } |
| int foo() { |
| int x; |
| x.foo = 42; |
| return x; |
| } |
| int bar() { |
| int x; |
| return x.foo; |
| } |
| `); |
| } |
| |
| whlslTests.setterWithNoGetterOverload = async () => |
| { |
| await checkFail( |
| ` |
| struct Foo { } |
| struct Bar { } |
| int operator.foo(Foo) |
| { |
| return 534; |
| } |
| Bar operator.foo=(Bar, int) |
| { |
| return Bar(); |
| } |
| `); |
| |
| } |
| |
| whlslTests.setterWithNoGetterOverloadFixed = async () => |
| { |
| await checkFail(` |
| struct Bar { } |
| int operator.foo(Bar) |
| { |
| return 534; |
| } |
| Bar operator.foo=(Bar, int) |
| { |
| return Bar(); |
| } |
| int foo() { |
| Bar bar; |
| return bar.foo; |
| } |
| int bar() { |
| Bar bar; |
| bar.foo = 52; |
| return bar.foo; |
| } |
| `); |
| } |
| |
| whlslTests.recursiveSetters = async () => |
| { |
| await checkFail(` |
| struct Foo { |
| int x; |
| int y; |
| } |
| struct Bar { |
| int a; |
| int b; |
| } |
| int operator.c(Bar bar) { return bar.a; } |
| Bar operator.bar(Foo foo) { Bar b; b.a = foo.x; b.b = foo.y; return b; } |
| Bar operator.c=(Bar bar, int newval) { bar.a = newval; return bar; } |
| Foo operator.bar=(Foo foo, Bar newval) { foo.x = newval.a; foo.y = newval.b; return foo; } |
| int f() { |
| Foo foo; |
| foo.x = foo.y = 3; |
| foo.bar.c = 8; |
| return foo.x*10 + foo.y; |
| } |
| `); |
| } |
| |
| whlslTests.loneSetter = async () => |
| { |
| await checkFail( |
| ` |
| int operator.foo=(int, int) |
| { |
| return 543; |
| } |
| `); |
| |
| } |
| |
| whlslTests.loneSetterPointer = async () => |
| { |
| await checkFail( |
| ` |
| thread int* operator.foo=(thread int* ptr, int) |
| { |
| return ptr; |
| } |
| `); |
| |
| } |
| |
| runTests(whlslTests); |
| </script> |
| </html> |