• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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';
17import {II as III} from "./shared_module_sendable_export";
18'use shared'
19
20export const enum A{a, b} // ok, const enum is sendable type
21export enum B{a, b} // error, enum is not sendable type
22export let var1: number | A; // ok, union type of const enum and number
23export let var2: A.a; // error, enum member is not sendable type
24
25export class C{} // error, class is not sendable type
26@Sendable
27export class D{} // ok, sendable class is sendable type
28export let var3: A | C; //error
29
30export interface E{} // error, interface is not sendable type
31export interface F extends lang.ISendable{} // ok, interface extends ISendable is sendable type;
32type ff = F;
33type ee = E;
34export {ff}; // ok
35export {ee}; // error
36let var4: C | ee;
37let var5: D | ff;
38export {var4}; // error
39export {var5}; // ok
40
41export * as ns from './shared_module_sendable_export'; // err,  ns is not sendable type
42export * from './shared_module_unsendable_export'; // error, 'export * from ...' is not supported
43export default III; // ok
44export {a} from './shared_module_sendable_export'; // ok
45export {a as aa} from './shared_module_unsendable_export'; // error
46export let var6: A | A.a; // error, union type of sendable and unsendbale
47export let var7: string | B = 'aaa'; // error , union type of sendable and unsendbale
48export let var8 = var7; // ok, no explicit type, the inferred type of var8 is string
49namespace ns {
50    export class A{}  // ok, exports from namespace are not checked
51}
52
53function foo(): boolean {
54    return true;
55}
56
57export {foo};
58
59@Sendable
60export function sf():void {
61}
62
63@Sendable
64function sf2():void {
65}
66export {sf2};
67
68export const primitive_str = 'a'; // OK
69export const primitive_num = 1; // OK
70export const primitive_bool = true; // OK
71export const primitive_big = 1n; // OK
72
73export enum NormalEnum { // ERROR,
74  a,
75  b,
76  c,
77  d
78}
79
80export const enum ConstEnum { // OK
81  a,
82  b,
83  c,
84  d
85}
86
87export const unite1 = // ERROR
88  Math.random() < 0.5
89    ? NormalEnum.a
90    : primitive_str;
91
92export const unite2 = Math.random() < 0.5 ? primitive_str : primitive_big; // OK
93
94export {
95  primitive_str as strAlias,
96  primitive_num as numAlias,
97  primitive_bool as boolAlias,
98  primitive_big as bigAlias,
99  NormalEnum as NormalEnumAlas // ERROR
100};