13af6ab5fSopenharmony_ci/*
23af6ab5fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License.
53af6ab5fSopenharmony_ci * You may obtain a copy of the License at
63af6ab5fSopenharmony_ci *
73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
83af6ab5fSopenharmony_ci *
93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and
133af6ab5fSopenharmony_ci * limitations under the License.
143af6ab5fSopenharmony_ci */
153af6ab5fSopenharmony_ci
163af6ab5fSopenharmony_ciimport type { D_Sft, D_Nft } from './sendable_function_dependencie';
173af6ab5fSopenharmony_ciimport {
183af6ab5fSopenharmony_ci  D_sf, Dv_sf, D_nf, Dv_nf, Dv_Sft, Dv_Nft, D_Sc, D_Nc,
193af6ab5fSopenharmony_ci  D_sf as AS_D_sf, Dv_sf as AS_Dv_sf, D_nf as AS_D_nf, Dv_nf as AS_Dv_nf,
203af6ab5fSopenharmony_ci  D_Sft as AS_D_Sft, Dv_Sft as AS_Dv_Sft, D_Nft as AS_D_Nft, Dv_Nft as AS_Dv_Nft,
213af6ab5fSopenharmony_ci  D_Sc as AS_D_Sc, D_Nc as AS_D_Nc
223af6ab5fSopenharmony_ci} from './sendable_function_dependencie';
233af6ab5fSopenharmony_ci
243af6ab5fSopenharmony_ci// -------------------- check sendable-function declaration -------------------- //
253af6ab5fSopenharmony_ci@Sendable 
263af6ab5fSopenharmony_cifunction sf():void {} // OK
273af6ab5fSopenharmony_ci@Sendable 
283af6ab5fSopenharmony_cifunction stf<T>(p:T):T {
293af6ab5fSopenharmony_ci  return p;
303af6ab5fSopenharmony_ci} // OK
313af6ab5fSopenharmony_ci@Sendable 
323af6ab5fSopenharmony_ci@Other  // ERROR
333af6ab5fSopenharmony_cifunction sf2():void {}
343af6ab5fSopenharmony_ci
353af6ab5fSopenharmony_ci
363af6ab5fSopenharmony_ci// check overloading
373af6ab5fSopenharmony_ci@Sendable 
383af6ab5fSopenharmony_cifunction sf3():void; // OK
393af6ab5fSopenharmony_ci@Sendable 
403af6ab5fSopenharmony_cifunction sf3():void;
413af6ab5fSopenharmony_ci
423af6ab5fSopenharmony_ci@Sendable 
433af6ab5fSopenharmony_cifunction sf3():void {}
443af6ab5fSopenharmony_ci
453af6ab5fSopenharmony_ci@Sendable 
463af6ab5fSopenharmony_cifunction sf4():void;
473af6ab5fSopenharmony_cifunction sf4():void; // ERROR
483af6ab5fSopenharmony_ci@Sendable 
493af6ab5fSopenharmony_cifunction sf4():void {}
503af6ab5fSopenharmony_ci
513af6ab5fSopenharmony_ci@Sendable 
523af6ab5fSopenharmony_cifunction sf5():void;
533af6ab5fSopenharmony_ci
543af6ab5fSopenharmony_ci@Sendable 
553af6ab5fSopenharmony_ci@Other  // ERROR
563af6ab5fSopenharmony_cifunction sf5():void;
573af6ab5fSopenharmony_ci
583af6ab5fSopenharmony_ci@Sendable 
593af6ab5fSopenharmony_cifunction sf5():void {}
603af6ab5fSopenharmony_ci
613af6ab5fSopenharmony_cifunction nf():void {}
623af6ab5fSopenharmony_ci
633af6ab5fSopenharmony_ci// -------------------- check sendable-typealias declaration -------------------- //
643af6ab5fSopenharmony_ci@Sendable 
653af6ab5fSopenharmony_citype Sft = () => void; // OK
663af6ab5fSopenharmony_ci@Sendable 
673af6ab5fSopenharmony_citype Sft2<T> = () => void; // OK
683af6ab5fSopenharmony_ci@Sendable 
693af6ab5fSopenharmony_citype Sft3 = <T>(p:T) => T; // OK
703af6ab5fSopenharmony_ci@Sendable 
713af6ab5fSopenharmony_ci@Other // ERROR
723af6ab5fSopenharmony_citype Sft4 = () => void; 
733af6ab5fSopenharmony_ci@Sendable 
743af6ab5fSopenharmony_citype Sft5 = number; // ERROR
753af6ab5fSopenharmony_ci@Sendable 
763af6ab5fSopenharmony_citype Sft6 = Sft; // ERROR
773af6ab5fSopenharmony_citype Sft7 = () => void;
783af6ab5fSopenharmony_ci
793af6ab5fSopenharmony_ci@Sendable 
803af6ab5fSopenharmony_citype Sft8 = Sft4; // ERROR
813af6ab5fSopenharmony_ci
823af6ab5fSopenharmony_citype Nft = ()=>void;
833af6ab5fSopenharmony_ci
843af6ab5fSopenharmony_ci// -------------------- check sendable-function closure -------------------- //
853af6ab5fSopenharmony_ci@Sendable 
863af6ab5fSopenharmony_ciclass Sc {}
873af6ab5fSopenharmony_ciclass Nc {}
883af6ab5fSopenharmony_ci
893af6ab5fSopenharmony_ci@Sendable 
903af6ab5fSopenharmony_ciclass SendableClassClosure {
913af6ab5fSopenharmony_ci  constructor() {
923af6ab5fSopenharmony_ci    const a1:Sft = sf; // OK
933af6ab5fSopenharmony_ci    const a2:Nft = nf; // ERROR
943af6ab5fSopenharmony_ci    const a3:Sc = new Sc(); // OK
953af6ab5fSopenharmony_ci    const a4:Nc = new Nc(); // ERROR
963af6ab5fSopenharmony_ci
973af6ab5fSopenharmony_ci    const b1:D_Sft = D_sf; // OK
983af6ab5fSopenharmony_ci    const b2:D_Nft = D_nf; // OK
993af6ab5fSopenharmony_ci    const b3:D_Sc = new D_Sc(); // OK
1003af6ab5fSopenharmony_ci    const b4:D_Nc = new D_Nc(); // OK
1013af6ab5fSopenharmony_ci  }
1023af6ab5fSopenharmony_ci
1033af6ab5fSopenharmony_ci  @nf
1043af6ab5fSopenharmony_ci  handle() {}
1053af6ab5fSopenharmony_ci}
1063af6ab5fSopenharmony_ci
1073af6ab5fSopenharmony_ci@Sendable 
1083af6ab5fSopenharmony_ci@nf
1093af6ab5fSopenharmony_cifunction SendableFunctionClosure() {
1103af6ab5fSopenharmony_ci  const a1:Sft = sf; // OK
1113af6ab5fSopenharmony_ci  const a2:Nft = nf; // ERROR
1123af6ab5fSopenharmony_ci  const a3:Sc = new Sc(); // OK
1133af6ab5fSopenharmony_ci  const a4:Nc = new Nc(); // ERROR
1143af6ab5fSopenharmony_ci  const b1:D_Sft = D_sf; // OK
1153af6ab5fSopenharmony_ci  const b2:D_Nft = D_nf; // OK
1163af6ab5fSopenharmony_ci  const b3:D_Sc = new D_Sc(); // OK
1173af6ab5fSopenharmony_ci  const b4:D_Nc = new D_Nc(); // OK
1183af6ab5fSopenharmony_ci}
1193af6ab5fSopenharmony_ci
1203af6ab5fSopenharmony_cinamespace ns {
1213af6ab5fSopenharmony_ci  @Sendable
1223af6ab5fSopenharmony_ci  function sf():void;
1233af6ab5fSopenharmony_ci  @Sendable
1243af6ab5fSopenharmony_ci  function sf():void {}
1253af6ab5fSopenharmony_ci}
1263af6ab5fSopenharmony_ci
1273af6ab5fSopenharmony_ci
1283af6ab5fSopenharmony_ci
1293af6ab5fSopenharmony_ci// -------------------- check sendable-typealias is sendaboe-data-type -------------------- //
1303af6ab5fSopenharmony_ci
1313af6ab5fSopenharmony_ci
1323af6ab5fSopenharmony_ci// check property
1333af6ab5fSopenharmony_ci@Sendable 
1343af6ab5fSopenharmony_ciclass Sc2<T> {
1353af6ab5fSopenharmony_ci  p1: Sft = sf; // OK
1363af6ab5fSopenharmony_ci  p2: D_Nft = sf; // ERROR
1373af6ab5fSopenharmony_ci}
1383af6ab5fSopenharmony_ci// check genericity
1393af6ab5fSopenharmony_cinew Sc2<Sft>();
1403af6ab5fSopenharmony_cinew Sc2<D_Nft>(); // ERROR
1413af6ab5fSopenharmony_ci
1423af6ab5fSopenharmony_ci// -------------------- check sendable-function cannot operation property --------------------//
1433af6ab5fSopenharmony_cisf.prop = 1; // ERROR
1443af6ab5fSopenharmony_ciD_nf.prop = 1; // OK
1453af6ab5fSopenharmony_ciD_sf.prop = 1; // ERROR
1463af6ab5fSopenharmony_ciAS_D_sf.prop = 1;// ERROR
1473af6ab5fSopenharmony_ci
1483af6ab5fSopenharmony_ci// -------------------- check sendable-function assignment --------------------//
1493af6ab5fSopenharmony_ci
1503af6ab5fSopenharmony_ci@Sendable
1513af6ab5fSopenharmony_cifunction stf1<T>(p:T):T {return p;};
1523af6ab5fSopenharmony_cifunction ntf1<T>(p:T):T {return p};
1533af6ab5fSopenharmony_ci//
1543af6ab5fSopenharmony_ciconst of1 = ()=>{};
1553af6ab5fSopenharmony_ci//
1563af6ab5fSopenharmony_ci@Sendable
1573af6ab5fSopenharmony_citype Stft1 = <T>(p:T)=>T;
1583af6ab5fSopenharmony_ci@Sendable
1593af6ab5fSopenharmony_citype Stft2<T> = ()=>void;
1603af6ab5fSopenharmony_ci//
1613af6ab5fSopenharmony_citype Nft1 = ()=>void;
1623af6ab5fSopenharmony_citype Nft2 = ()=>number;
1633af6ab5fSopenharmony_citype Ntft1 = <T>(p:T)=>T;
1643af6ab5fSopenharmony_citype Ntft2<T> = ()=>void;
1653af6ab5fSopenharmony_ci//
1663af6ab5fSopenharmony_citype U_Sft1 = Sft | D_Sft;
1673af6ab5fSopenharmony_citype U_Sft2 = Sft | Stft1;
1683af6ab5fSopenharmony_citype U_Nft1 = Nft1 | Nft2;
1693af6ab5fSopenharmony_citype U_Nft2 = Nft1 | Ntft1;
1703af6ab5fSopenharmony_citype U_ft1 = Sft | Nft1;
1713af6ab5fSopenharmony_citype U_ft2 = Sft | Stft1| Nft1 | Ntft1;
1723af6ab5fSopenharmony_ci//
1733af6ab5fSopenharmony_citype TU_Sft1<T> = Sft | D_Sft;
1743af6ab5fSopenharmony_citype TU_Sft2<T> = Sft | Stft1 | Stft1 ;
1753af6ab5fSopenharmony_citype TU_Nft1<T> = Nft1 | Nft2;
1763af6ab5fSopenharmony_citype TU_Nft2<T> = Nft1 | Ntft1| Ntft2<string>;
1773af6ab5fSopenharmony_citype TU_ft1<T> = Sft | Stft1 | Nft1 | Ntft1;
1783af6ab5fSopenharmony_ci//
1793af6ab5fSopenharmony_citype DU_Sft1 = U_Sft1 | U_Sft2;
1803af6ab5fSopenharmony_citype DU_Sft2<T> = DU_Sft1 | TU_Sft1<T>;
1813af6ab5fSopenharmony_citype DU_Sft3<T> = DU_Sft2<T> | TU_Sft2<T>;
1823af6ab5fSopenharmony_citype DU_Nft<T> = DU_Sft3<T> | TU_Nft2<T>;
1833af6ab5fSopenharmony_ci// normal
1843af6ab5fSopenharmony_ciconst a1: Sft = sf; // OK
1853af6ab5fSopenharmony_ciconst a2: Sft = nf; // ERROR
1863af6ab5fSopenharmony_ciconst a3: Sft = of1; // ERROR
1873af6ab5fSopenharmony_ciconst a4: Nft1 = nf; // OK
1883af6ab5fSopenharmony_ciconst a5: Sft = a1; // OK
1893af6ab5fSopenharmony_ciconst a6: Sft = a4; // ERROR
1903af6ab5fSopenharmony_ci// generic
1913af6ab5fSopenharmony_ciconst b1: Stft1 = stf1; // OK
1923af6ab5fSopenharmony_ciconst b2: Stft1 = ntf1; // ERROR
1933af6ab5fSopenharmony_ciconst b3: Ntft1 = ntf1; // OK
1943af6ab5fSopenharmony_ciconst b4: Stft1 = b1; // OK
1953af6ab5fSopenharmony_ciconst b5: Stft1 = b3; // ERROR
1963af6ab5fSopenharmony_ci// unite
1973af6ab5fSopenharmony_ciconst f1: U_ft1 = sf; // OK
1983af6ab5fSopenharmony_ciconst f2: U_ft2 = stf1; // OK
1993af6ab5fSopenharmony_ciconst f3: U_ft1 = nf; // ERROR
2003af6ab5fSopenharmony_ciconst f4: U_ft2 = ntf1; // ERROR
2013af6ab5fSopenharmony_ciconst d1: U_Sft1 = sf; // OK
2023af6ab5fSopenharmony_ciconst d2: U_Sft1 = nf; // ERROR
2033af6ab5fSopenharmony_ciconst d3: U_Sft1 = of1; // ERROR
2043af6ab5fSopenharmony_ciconst d4: U_Nft1 = sf; // OK
2053af6ab5fSopenharmony_ciconst d5: U_Nft1 = nf; // OK
2063af6ab5fSopenharmony_ciconst d6: U_Nft1 = of1; // OK
2073af6ab5fSopenharmony_ciconst d7: U_Sft1 = d1; // OK
2083af6ab5fSopenharmony_ciconst d18: U_Sft1 = d4; // ERROR
2093af6ab5fSopenharmony_ciconst d9: U_Sft1 = f1; // ERROR
2103af6ab5fSopenharmony_ci// const d10: U_Sft1 = f2; // ERROR
2113af6ab5fSopenharmony_ciconst e1: U_Sft2 = stf1; // OK
2123af6ab5fSopenharmony_ciconst e2: U_Sft2 = ntf1; // ERROR
2133af6ab5fSopenharmony_ciconst e3: U_Nft2 = ntf1; // OK
2143af6ab5fSopenharmony_ciconst e4: U_Sft2 = e1; // OK
2153af6ab5fSopenharmony_ciconst e5: U_Sft2 = e3; // ERROR
2163af6ab5fSopenharmony_ciconst e6: U_Sft2 = f1; // ERROR
2173af6ab5fSopenharmony_ciconst e7: U_Sft2 = f2; // ERROR
2183af6ab5fSopenharmony_ci// unite & generic
2193af6ab5fSopenharmony_ciconst g1: TU_ft1<number> = sf; // OK
2203af6ab5fSopenharmony_ciconst g2: TU_ft1<number> = stf1; // OK
2213af6ab5fSopenharmony_ciconst g3: TU_ft1<number> = nf; // ERROR
2223af6ab5fSopenharmony_ciconst h1: TU_Sft1<number> = sf; // OK
2233af6ab5fSopenharmony_ciconst h2: TU_Sft1<number> = nf; // ERROR
2243af6ab5fSopenharmony_ciconst h3: TU_Sft1<number> = of1; // ERROR
2253af6ab5fSopenharmony_ciconst h4: TU_Nft1<number> = nf; // OK
2263af6ab5fSopenharmony_ciconst h5: TU_Sft1<number> = h1; // OK
2273af6ab5fSopenharmony_ciconst h6: TU_Sft1<number> = h4; // ERROR
2283af6ab5fSopenharmony_ciconst h7: TU_Sft2<number> = stf1; // OK
2293af6ab5fSopenharmony_ciconst h8: TU_Sft2<number> = ntf1; // ERROR
230