| 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 | global Glob { |
| 5 | function g1() {} |
| 6 | protected function g2() {} |
| 7 | public function g3() {} |
| 8 | |
| 9 | function c() { |
| 10 | g1();g2();g3(); |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | Comp := Rectangle { |
| 15 | function f1() {} |
| 16 | public function f2() {} |
| 17 | protected function f3() {} |
| 18 | |
| 19 | function c() { |
| 20 | f1();f2();f3(); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | export Xxx := Rectangle { |
| 25 | function foo(a: int) -> string { return a; } |
| 26 | |
| 27 | comp := Comp {} |
| 28 | |
| 29 | function bar() { |
| 30 | foo(45, 45); |
| 31 | // ^error{The callback or function expects 1 arguments, but 2 are provided} |
| 32 | |
| 33 | foo.hello(45); |
| 34 | // ^error{Cannot access fields of a function} |
| 35 | |
| 36 | root.foo(); |
| 37 | // ^error{The callback or function expects 1 arguments, but 0 are provided} |
| 38 | |
| 39 | root.foo.hello(45); |
| 40 | // ^error{Cannot access fields of a function} |
| 41 | |
| 42 | comp.f1(); |
| 43 | // ^error{The function 'f1' is private. Annotate it with 'public' to make it accessible from other components} |
| 44 | comp.f2(); |
| 45 | |
| 46 | comp.f3(); |
| 47 | // ^error{The function 'f3' is protected} |
| 48 | |
| 49 | notexist(); |
| 50 | // ^error{Unknown unqualified identifier 'notexist'} |
| 51 | comp.notexist(56, foo("fff" )); |
| 52 | // ^error{Element 'Comp' does not have a property 'notexist'} |
| 53 | // ^^error{Cannot convert string to int} |
| 54 | 45()()(); |
| 55 | // ^error{The expression is not a function} |
| 56 | (foo)(1); |
| 57 | // ^error{Function must be called. Did you forgot the '\(\)'} |
| 58 | |
| 59 | } |
| 60 | |
| 61 | callback xx <=> foo; |
| 62 | // ^error{Binding to callback 'xx' must bind to another callback} |
| 63 | } |
| 64 | |
| 65 | |
| 66 | export component DerComp inherits Comp { |
| 67 | public function f4() { |
| 68 | root.f1(); |
| 69 | // ^error{The function 'f1' is private. Annotate it with 'public' to make it accessible from other components} |
| 70 | root.f2(); |
| 71 | root.f3(); |
| 72 | |
| 73 | self.f1(); |
| 74 | // ^error{The function 'f1' is private. Annotate it with 'public' to make it accessible from other components} |
| 75 | self.f2(); |
| 76 | self.f3(); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | export component DerDerComp inherits DerComp { |
| 81 | public function f5() { |
| 82 | root.f1(); |
| 83 | // ^error{The function 'f1' is private. Annotate it with 'public' to make it accessible from other components} |
| 84 | root.f2(); |
| 85 | root.f3(); |
| 86 | // ^error{The function 'f3' is protected} |
| 87 | self.f1(); |
| 88 | // ^error{The function 'f1' is private. Annotate it with 'public' to make it accessible from other components} |
| 89 | self.f2(); |
| 90 | self.f3(); |
| 91 | // ^error{The function 'f3' is protected} |
| 92 | |
| 93 | Glob.g1(); |
| 94 | // ^warning{The function 'g1' is private. Annotate it with 'public' to make it accessible from other components. Note: this used to be allowed in previous version, but this should be considered an error} |
| 95 | Glob.g2(); |
| 96 | // ^error{The function 'g2' is protected} |
| 97 | Glob.g3(); |
| 98 | } |
| 99 | } |