| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | // Test that structs work if they are only referenced by functions |
| 5 | |
| 6 | struct Foo1 { member: int, } |
| 7 | struct Foo2 { a: Foo1 } |
| 8 | struct Foo3 { b: int } |
| 9 | |
| 10 | TestCase := TouchArea { |
| 11 | // Based on Issue #2655 |
| 12 | public function fn1(foo2: Foo2) -> Foo3 { |
| 13 | return { b: foo2.a.member+1 }; |
| 14 | } |
| 15 | public function fn2() { fn1({a:{member:456}}); } |
| 16 | } |
| 17 | |
| 18 | |
| 19 | /* |
| 20 | ```rust |
| 21 | let instance = TestCase::new().unwrap(); |
| 22 | |
| 23 | assert_eq!(instance.invoke_fn1(Foo2{ a: Foo1{ member: 123 } }).b, 124); |
| 24 | ``` |
| 25 | |
| 26 | ```cpp |
| 27 | auto handle = TestCase::create(); |
| 28 | const TestCase &instance = *handle; |
| 29 | |
| 30 | assert_eq(instance.invoke_fn1(Foo2{ Foo1{ 123 } }).b, 124); |
| 31 | ``` |
| 32 | |
| 33 | ```js |
| 34 | var instance = new slint.TestCase({}); |
| 35 | assert.equal(instance.fn1({ a: { member: 123 } }).b, 124); |
| 36 | ``` |
| 37 | |
| 38 | */ |
| 39 | |