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 {lang} from './@arkts.lang'; 173af6ab5fSopenharmony_ciimport {II as III} from "./shared_module_sendable_export"; 183af6ab5fSopenharmony_ci'use shared' 193af6ab5fSopenharmony_ci 203af6ab5fSopenharmony_ciexport const enum A{a, b} // ok, const enum is sendable type 213af6ab5fSopenharmony_ciexport enum B{a, b} // error, enum is not sendable type 223af6ab5fSopenharmony_ciexport let var1: number | A; // ok, union type of const enum and number 233af6ab5fSopenharmony_ciexport let var2: A.a; // error, enum member is not sendable type 243af6ab5fSopenharmony_ci 253af6ab5fSopenharmony_ciexport class C{} // error, class is not sendable type 263af6ab5fSopenharmony_ci@Sendable 273af6ab5fSopenharmony_ciexport class D{} // ok, sendable class is sendable type 283af6ab5fSopenharmony_ciexport let var3: A | C; //error 293af6ab5fSopenharmony_ci 303af6ab5fSopenharmony_ciexport interface E{} // error, interface is not sendable type 313af6ab5fSopenharmony_ciexport interface F extends lang.ISendable{} // ok, interface extends ISendable is sendable type; 323af6ab5fSopenharmony_citype ff = F; 333af6ab5fSopenharmony_citype ee = E; 343af6ab5fSopenharmony_ciexport {ff}; // ok 353af6ab5fSopenharmony_ciexport {ee}; // error 363af6ab5fSopenharmony_cilet var4: C | ee; 373af6ab5fSopenharmony_cilet var5: D | ff; 383af6ab5fSopenharmony_ciexport {var4}; // error 393af6ab5fSopenharmony_ciexport {var5}; // ok 403af6ab5fSopenharmony_ci 413af6ab5fSopenharmony_ciexport * as ns from './shared_module_sendable_export'; // err, ns is not sendable type 423af6ab5fSopenharmony_ciexport * from './shared_module_unsendable_export'; // error, 'export * from ...' is not supported 433af6ab5fSopenharmony_ciexport default III; // ok 443af6ab5fSopenharmony_ciexport {a} from './shared_module_sendable_export'; // ok 453af6ab5fSopenharmony_ciexport {a as aa} from './shared_module_unsendable_export'; // error 463af6ab5fSopenharmony_ciexport let var6: A | A.a; // error, union type of sendable and unsendbale 473af6ab5fSopenharmony_ciexport let var7: string | B = 'aaa'; // error , union type of sendable and unsendbale 483af6ab5fSopenharmony_ciexport let var8 = var7; // ok, no explicit type, the inferred type of var8 is string 493af6ab5fSopenharmony_cinamespace ns { 503af6ab5fSopenharmony_ci export class A{} // ok, exports from namespace are not checked 513af6ab5fSopenharmony_ci} 523af6ab5fSopenharmony_ci 533af6ab5fSopenharmony_cifunction foo(): boolean { 543af6ab5fSopenharmony_ci return true; 553af6ab5fSopenharmony_ci} 563af6ab5fSopenharmony_ci 573af6ab5fSopenharmony_ciexport {foo}; 583af6ab5fSopenharmony_ci 593af6ab5fSopenharmony_ci@Sendable 603af6ab5fSopenharmony_ciexport function sf():void { 613af6ab5fSopenharmony_ci} 623af6ab5fSopenharmony_ci 633af6ab5fSopenharmony_ci@Sendable 643af6ab5fSopenharmony_cifunction sf2():void { 653af6ab5fSopenharmony_ci} 663af6ab5fSopenharmony_ci 673af6ab5fSopenharmony_ciexport {sf2}; 683af6ab5fSopenharmony_ci 693af6ab5fSopenharmony_ciexport const primitive_str = 'a'; // OK 703af6ab5fSopenharmony_ciexport const primitive_num = 1; // OK 713af6ab5fSopenharmony_ciexport const primitive_bool = true; // OK 723af6ab5fSopenharmony_ciexport const primitive_big = 1n; // OK 733af6ab5fSopenharmony_ci 743af6ab5fSopenharmony_ciexport enum NormalEnum { // ERROR, 753af6ab5fSopenharmony_ci a, 763af6ab5fSopenharmony_ci b, 773af6ab5fSopenharmony_ci c, 783af6ab5fSopenharmony_ci d 793af6ab5fSopenharmony_ci} 803af6ab5fSopenharmony_ci 813af6ab5fSopenharmony_ciexport const enum ConstEnum { // OK 823af6ab5fSopenharmony_ci a, 833af6ab5fSopenharmony_ci b, 843af6ab5fSopenharmony_ci c, 853af6ab5fSopenharmony_ci d 863af6ab5fSopenharmony_ci} 873af6ab5fSopenharmony_ci 883af6ab5fSopenharmony_ciexport const unite1 = // ERROR 893af6ab5fSopenharmony_ci Math.random() < 0.5 903af6ab5fSopenharmony_ci ? NormalEnum.a 913af6ab5fSopenharmony_ci : primitive_str; 923af6ab5fSopenharmony_ci 933af6ab5fSopenharmony_ciexport const unite2 = Math.random() < 0.5 ? primitive_str : primitive_big; // OK 943af6ab5fSopenharmony_ci 953af6ab5fSopenharmony_ciexport { 963af6ab5fSopenharmony_ci primitive_str as strAlias, 973af6ab5fSopenharmony_ci primitive_num as numAlias, 983af6ab5fSopenharmony_ci primitive_bool as boolAlias, 993af6ab5fSopenharmony_ci primitive_big as bigAlias, 1003af6ab5fSopenharmony_ci NormalEnum as NormalEnumAlas // ERROR 1013af6ab5fSopenharmony_ci}; 1023af6ab5fSopenharmony_ci 1033af6ab5fSopenharmony_ciexport type TypeC = C; // ERROR 1043af6ab5fSopenharmony_ciexport type TypeE = E; // ERROR 105