1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import {lang} from './@arkts.lang';
17
18class NonSendableClass2 {}
19
20@Sendable
21class SendableClass10 {}
22
23@Sendable
24class SendableClass4<T, U> {
25  prop1: number; // OK
26  prop2: string; // OK
27  prop3: boolean; // OK
28  prop4: bigint; // OK
29  prop5: SendableClass3; // OK
30  prop6: null; // OK
31  prop7: undefined; // OK
32  prop8: U; // OK
33  prop9: T | number | undefined; // OK
34  prop10: alias0; // OK
35  prop11: alias1; // OK
36  prop12: ISendableExt1; // OK
37  prop13: ConstEnum; // OK
38  prop14: ConstEnum1; // OK
39  prop15: ConstEnum2; // OK
40  prop16: ConstEnum2 = ConstEnum2.Memc2; // OK
41  prop17: ConstEnum | ConstEnum1 | ConstEnum2; // OK
42  prop18: ConstEnum | SendableClass3; // OK
43  prop19: ConstEnum1 | SendableClass10; // OK
44  prop20: N.ConstEnum | ConstEnum; // OK
45  prop21: alias4; // OK
46  prop22: alias5; // OK
47  prop23: alias6; // OK
48  prop24: SendableClass3 | alias4 | alias5; // OK
49  prop25: number | boolean; // OK
50  prop26: boolean | bigint; // OK
51  prop27: boolean | null; // OK
52  prop28: bigint | null; // OK
53  prop29: alias14; // OK
54  prop30: alias15; // OK
55  prop31: (number);
56  prop32: (boolean | bigint);
57  prop33: number | (SendableClass3 | ((null | string)));
58  prop34: alias16;
59  prop35: alias17;
60  prop36: alias18;
61}
62
63@Sendable
64class SendableClass3 {
65  prop1: string[]; // ERROR, sendable class property cannot be array
66  prop2: NonSendableClass2; // ERROR, sendable class property cannot be non-sendable-class
67  prop3: NonSendableClass2 | null; // ERROR, sendable class property cannot be non-sendable-class union type
68  prop4: NonSendableInterface | number; // ERROR, sendable class property cannot be non-sendable-class union type
69  prop5: NonSendableClass2 | null | undefined; // ERROR, sendable class property cannot be non-sendable-class union type
70  prop6: alias2; // ERROR, sendable class property cannot be non-sendable-type
71  prop7: alias3; // ERROR, sendable class property cannot be non-sendable-type
72  prop8: RegularEnum; // ERROR, sendable class property cannot be non-sendable-type
73  prop9: RegularEnum1; // ERROR, sendable class property cannot be non-sendable-type
74  prop10: RegularEnum2; // ERROR, sendable class property cannot be non-sendable-type
75  prop11: RegularEnum2 = RegularEnum2.Memr3; // ERROR, sendable class property cannot be non-sendable-type
76  prop12: ConstEnum1.Memc1; // ERROR, sendable class property cannot be enum member type
77  prop13: ConstEnum2.Memc2; // ERROR, sendable class property cannot be enum member type
78  prop14: ConstEnum | ConstEnum1.Memc1; // ERROR, sendable class property cannot be non-sendable union type
79  prop15: ConstEnum2 | RegularEnum1; // ERROR, sendable class property cannot be non-sendable union type
80  prop16: RegularEnum2.Memr2 | SendableClass10; // ERROR, sendable class property cannot be non-sendable union type
81  prop17: alias7; // ERROR, sendable class property cannot be non-sendable alias type
82  prop18: alias8; // ERROR, sendable class property cannot be non-sendable alias type
83  prop19: alias9; // ERROR, sendable class property cannot be non-sendable alias type
84  prop20: alias6 | NonSendableInterface; // ERROR, sendable class property cannot be non-sendable union type
85  prop21: alias7 | SendableClass3; // ERROR, sendable class property cannot be non-sendable union type
86  prop22: SendableClass10 | alias8; // ERROR, sendable class property cannot be non-sendable union type
87  prop23: 1; // ERROR, sendable class property cannot be numeric literal type
88  prop24: 'x'; // ERROR, sendable class property cannot be string literal type
89  prop25: true; // ERROR, sendable class property cannot be boolean literal type
90  prop26: 2n; // ERROR, sendable class property cannot be bigint literal type
91  prop27: true | false; // ERROR, sendable class property cannot be non-sendable union type
92  prop271: 3 | 'y' | false | 4; // ERROR, sendable class property cannot be non-sendable union type
93  prop28: SendableClass3 | 5; // ERROR, sendable class property cannot be non-sendable union type
94  prop29: alias10; // ERROR, sendable class property cannot be non-sendable alias type
95  prop30: alias11; // ERROR, sendable class property cannot be non-sendable alias type
96  prop31: alias12; // ERROR, sendable class property cannot be non-sendable alias type
97  prop32: alias13; // ERROR, sendable class property cannot be non-sendable alias type
98  prop33: (10);
99  prop34: (true | 'false');
100  prop35: number | (SendableClass3 | ((string | NonSendableClass2)));
101  prop36: alias19;
102  prop37: alias20;
103  ["aaa"]: number; // ERROR, sendable class property name cannot be computed property 
104}
105
106type alias0 = number | null;
107type alias1 = SendableClass10;
108type alias2 = NonSendableClass2;
109type alias3 = NonSendableClass2 | undefined;
110type alias4 = ConstEnum;
111type alias5 = ConstEnum1 | ConstEnum2;
112type alias6 = ConstEnum | SendableClass3;
113type alias7 = RegularEnum | RegularEnum1 | ConstEnum;
114type alias8 = ConstEnum1.Memc1;
115type alias9 = ConstEnum | ConstEnum2.Memc3;
116type alias10 = 10;
117type alias11 = 'foo';
118type alias12 = 20 | 'bar';
119type alias13 = true | false;
120type alias14 = number | boolean;
121type alias15 = boolean | null | undefined;
122type alias16 = (number);
123type alias17 = (boolean | null);
124type alias18 = (SendableClass3 | string);
125type alias19 = number | (string | ((SendableClass3 | NonSendableClass2)));
126type alias20 = (1 | '2' | true);
127
128const enum ConstEnum {};
129const enum ConstEnum1 {
130  Memc1 = 1
131};
132const enum ConstEnum2 {
133  Memc2 = 'aa',
134  Memc3 = 2
135};
136
137enum RegularEnum {};
138enum RegularEnum1 {
139  Memr1 = 'aa'
140};
141enum RegularEnum2 {
142  Memr2 = 'aa',
143  Memr3 = 2
144};
145
146export declare namespace N {
147  export const enum ConstEnum {
148    E1 = 1
149  }
150}
151
152// Implement interface extending ISendable
153interface ISendableExt1 extends lang.ISendable {
154  prop1: number; // OK
155  prop2: string; // OK
156  prop3: boolean; // OK
157  prop4: bigint; // OK
158  prop5: SendableClass3; // OK
159  prop6: null; // OK
160  prop7: undefined; // OK
161  prop8: SendableClass3 | string; // OK
162  prop9: number | null | undefined; // OK
163  prop10: alias0; // OK
164  prop11: alias1; // OK
165  prop12: ISendableExt2; // OK
166  prop13: ConstEnum; // OK
167  prop14: ConstEnum1; // OK
168  prop15: ConstEnum2; // OK
169}
170// Implement interface extending ISendable
171interface ISendableExt2 extends lang.ISendable {
172  prop1: string[]; // ERROR, sendable interface property cannot be array
173  prop2: NonSendableClass2; // ERROR, sendable interface property cannot be non-sendable-class
174  prop3: NonSendableClass2 | null; // ERROR, sendable interface property cannot be non-sendable-class union type
175  prop4: NonSendableInterface | string; // ERROR, sendable interface property cannot be non-sendable-class union type
176  prop5: NonSendableClass2 | null | undefined; // ERROR, sendable interface property cannot be non-sendable-class union type
177  prop6: alias2; // ERROR, sendable interface property cannot be non-sendable-type
178  prop7: alias3; // ERROR, sendable interface property cannot be non-sendable-type
179  prop8: RegularEnum; // ERROR, sendable interface property cannot be non-sendable-type
180  prop9: RegularEnum1; // ERROR, sendable interface property cannot be non-sendable-type
181  prop10: RegularEnum2; // ERROR, sendable interface property cannot be non-sendable-type
182  ["aaa"]: number; // ERROR, sendable interface property name cannot be computed property
183  [Symbol.iterator](): IterableIterator<number>;
184}
185
186interface NonSendableInterface {};
187