• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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 type { D_Sft, D_Nft } from './sendable_function_dependencie';
17import {
18  D_sf, Dv_sf, D_nf, Dv_nf, Dv_Sft, Dv_Nft, D_Sc, D_Nc,
19  D_sf as AS_D_sf, Dv_sf as AS_Dv_sf, D_nf as AS_D_nf, Dv_nf as AS_Dv_nf,
20  D_Sft as AS_D_Sft, Dv_Sft as AS_Dv_Sft, D_Nft as AS_D_Nft, Dv_Nft as AS_Dv_Nft,
21  D_Sc as AS_D_Sc, D_Nc as AS_D_Nc
22} from './sendable_function_dependencie';
23
24// -------------------- check sendable-function declaration -------------------- //
25@Sendable
26function sf():void {} // OK
27@Sendable
28function stf<T>(p:T):T {
29  return p;
30} // OK
31@Sendable
32@Other  // ERROR
33function sf2():void {}
34
35
36// check overloading
37@Sendable
38function sf3():void; // OK
39@Sendable
40function sf3():void;
41
42@Sendable
43function sf3():void {}
44
45@Sendable
46function sf4():void;
47@Sendable
48function sf4():void; // ERROR
49@Sendable
50function sf4():void {}
51
52@Sendable
53function sf5():void;
54
55@Sendable
56@Other  // ERROR
57function sf5():void;
58
59@Sendable
60function sf5():void {}
61
62function nf():void {}
63
64// -------------------- check sendable-typealias declaration -------------------- //
65@Sendable
66type Sft = () => void; // OK
67@Sendable
68type Sft2<T> = () => void; // OK
69@Sendable
70type Sft3 = <T>(p:T) => T; // OK
71@Sendable
72@Other // ERROR
73type Sft4 = () => void;
74@Sendable
75type Sft5 = number; // ERROR
76@Sendable
77type Sft6 = Sft; // ERROR
78type Sft7 = () => void;
79
80@Sendable
81type Sft8 = Sft4; // ERROR
82
83type Nft = ()=>void;
84
85// -------------------- check sendable-function closure -------------------- //
86@Sendable
87class Sc {}
88class Nc {}
89
90@Sendable
91class SendableClassClosure {
92  constructor() {
93    const a1:Sft = sf; // OK
94    const a2:Nft = nf; // ERROR
95    const a3:Sc = new Sc(); // OK
96    const a4:Nc = new Nc(); // ERROR
97
98    const b1:D_Sft = D_sf; // OK
99    const b2:D_Nft = D_nf; // OK
100    const b3:D_Sc = new D_Sc(); // OK
101    const b4:D_Nc = new D_Nc(); // OK
102  }
103
104  @nf
105  handle() {}
106}
107
108@Sendable
109@nf
110function SendableFunctionClosure() {
111  const a1:Sft = sf; // OK
112  const a2:Nft = nf; // ERROR
113  const a3:Sc = new Sc(); // OK
114  const a4:Nc = new Nc(); // ERROR
115  const b1:D_Sft = D_sf; // OK
116  const b2:D_Nft = D_nf; // OK
117  const b3:D_Sc = new D_Sc(); // OK
118  const b4:D_Nc = new D_Nc(); // OK
119}
120
121namespace ns {
122  @Sendable
123  function sf():void;
124  @Sendable
125  function sf():void {}
126}
127
128
129
130// -------------------- check sendable-typealias is sendaboe-data-type -------------------- //
131
132
133// check property
134@Sendable
135class Sc2<T> {
136  p1: Sft = sf; // OK
137  p2: D_Nft = sf; // ERROR
138}
139// check genericity
140new Sc2<Sft>();
141new Sc2<D_Nft>(); // ERROR
142
143// -------------------- check sendable-function cannot operation property --------------------//
144sf.prop = 1; // ERROR
145D_nf.prop = 1; // OK
146D_sf.prop = 1; // ERROR
147AS_D_sf.prop = 1;// ERROR
148
149// -------------------- check sendable-function assignment --------------------//
150
151@Sendable
152function stf1<T>(p:T):T {return p;};
153function ntf1<T>(p:T):T {return p};
154//
155const of1 = ()=>{};
156//
157@Sendable
158type Stft1 = <T>(p:T)=>T;
159@Sendable
160type Stft2<T> = ()=>void;
161//
162type Nft1 = ()=>void;
163type Nft2 = ()=>number;
164type Ntft1 = <T>(p:T)=>T;
165type Ntft2<T> = ()=>void;
166//
167type U_Sft1 = Sft | D_Sft;
168type U_Sft2 = Sft | Stft1;
169type U_Nft1 = Nft1 | Nft2;
170type U_Nft2 = Nft1 | Ntft1;
171type U_ft1 = Sft | Nft1;
172type U_ft2 = Sft | Stft1| Nft1 | Ntft1;
173//
174type TU_Sft1<T> = Sft | D_Sft;
175type TU_Sft2<T> = Sft | Stft1 | Stft1 ;
176type TU_Nft1<T> = Nft1 | Nft2;
177type TU_Nft2<T> = Nft1 | Ntft1| Ntft2<string>;
178type TU_ft1<T> = Sft | Stft1 | Nft1 | Ntft1;
179//
180type DU_Sft1 = U_Sft1 | U_Sft2;
181type DU_Sft2<T> = DU_Sft1 | TU_Sft1<T>;
182type DU_Sft3<T> = DU_Sft2<T> | TU_Sft2<T>;
183type DU_Nft<T> = DU_Sft3<T> | TU_Nft2<T>;
184// normal
185const a1: Sft = sf; // OK
186const a2: Sft = nf; // ERROR
187const a3: Sft = of1; // ERROR
188const a4: Nft1 = nf; // OK
189const a5: Sft = a1; // OK
190const a6: Sft = a4; // ERROR
191// generic
192const b1: Stft1 = stf1; // OK
193const b2: Stft1 = ntf1; // ERROR
194const b3: Ntft1 = ntf1; // OK
195const b4: Stft1 = b1; // OK
196const b5: Stft1 = b3; // ERROR
197// unite
198const f1: U_ft1 = sf; // OK
199const f2: U_ft2 = stf1; // OK
200const f3: U_ft1 = nf; // ERROR
201const f4: U_ft2 = ntf1; // ERROR
202const d1: U_Sft1 = sf; // OK
203const d2: U_Sft1 = nf; // ERROR
204const d3: U_Sft1 = of1; // ERROR
205const d4: U_Nft1 = sf; // OK
206const d5: U_Nft1 = nf; // OK
207const d6: U_Nft1 = of1; // OK
208const d7: U_Sft1 = d1; // OK
209const d18: U_Sft1 = d4; // ERROR
210const d9: U_Sft1 = f1; // ERROR
211// const d10: U_Sft1 = f2; // ERROR
212const e1: U_Sft2 = stf1; // OK
213const e2: U_Sft2 = ntf1; // ERROR
214const e3: U_Nft2 = ntf1; // OK
215const e4: U_Sft2 = e1; // OK
216const e5: U_Sft2 = e3; // ERROR
217const e6: U_Sft2 = f1; // ERROR
218const e7: U_Sft2 = f2; // ERROR
219// unite & generic
220const g1: TU_ft1<number> = sf; // OK
221const g2: TU_ft1<number> = stf1; // OK
222const g3: TU_ft1<number> = nf; // ERROR
223const h1: TU_Sft1<number> = sf; // OK
224const h2: TU_Sft1<number> = nf; // ERROR
225const h3: TU_Sft1<number> = of1; // ERROR
226const h4: TU_Nft1<number> = nf; // OK
227const h5: TU_Sft1<number> = h1; // OK
228const h6: TU_Sft1<number> = h4; // ERROR
229const h7: TU_Sft2<number> = stf1; // OK
230const h8: TU_Sft2<number> = ntf1; // ERROR
231