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
16
17import { libPi, libString, libFoo, LibClass, libClassVar, LibRGB } from './sendable_captured_variables_lib'
18import libVar from './sendable_captured_variables_lib'
19import * as sendableNamespce from './sendable_captured_variables_namespaceimport_lib'
20
21let localVar = 'local';
22
23function localFun(): string {
24  return "local foo";
25}
26
27class LocalClass {
28  a: number = 1;
29  static b: string = '2';
30  foo(): void {}
31  static bar(): void {}
32}
33
34let localObj: LocalClass = new LocalClass();
35
36enum LocalRGB {
37  RED,
38  GREEN,
39  BLUE
40}
41
42const enum ConstRGB {
43  RED,
44  GREEN,
45  BLUE
46}
47
48@Sendable
49class SendableClass {
50  static pi: number = libPi;
51  static hdr: string = libString;
52  public p = localVar; // ERROR
53  static ps = localVar; // ERROR
54  sc: SendableClass2 = new SendableClass2();
55  csc: ConstRGB = ConstRGB.GREEN;
56  arr: Array = new Array<number>();
57
58  public foo(x: string): string {
59    let s = localVar; // ERROR
60    let ss = this.p + SendableClass.ps + x;
61    s = localFun(); // ERROR
62    s = libFoo();
63    return s + ss;
64  }
65
66  bar(a: SendableClass2) {
67    let b = a;
68    a.a = 2;
69    let c = new sendableNamespce.SendableClassExp(); // ERROR
70  }
71
72  baz(): SendableClass2 {
73    return new SendableClass2();
74  }
75  
76  bazz(): void {
77    let a: LibRGB = LibRGB.GREEN;
78    console.log(LibRGB.RED);
79    
80    let b: LocalRGB;
81    b = LocalRGB.RED; // ERROR
82    console.log(LocalRGB.BLUE); // ERROR
83  }
84
85  static {
86    SendableClass.ps = localVar; // ERROR
87    let lc: LocalClass;
88    lc = new LocalClass(); // ERROR
89    console.log(lc.a);
90    console.log(LocalClass.b); // ERROR
91    lc.foo();
92    LocalClass.bar(); // ERROR
93    lc = localObj; // ERROR
94    console.log(localObj.a); // ERROR
95    localObj.foo(); // ERROR
96
97    let pps: string = libString;
98    let libv: number = libVar;
99    let libc: LibClass;
100    libc = libClassVar;
101
102    console.log(libc.a);
103    console.log(LibClass.b);
104    libc.foo();
105    LibClass.bar();
106  }
107}
108
109interface B {
110
111}
112
113@Sendable
114class SendableClass2 {
115    a: number = 1;
116}
117
118@Sendable
119class C {
120  static a: number = 1;
121  f(p: number) {
122    @Sendable
123    class D extends SendableClass2 implements B { // ERROR
124      b: number = C.a;
125      d: number = p; // ERROR
126    }
127  }
128}
129
130export let b = 1;
131@Sendable
132class A {
133  aa: number = b; // ERROR
134}
135
136namespace xx {
137  export let b = 1;
138  @Sendable
139  class A {
140    aa: number = b; // ERROR
141  }
142}
143
144function sealed(ctor: Function) {}
145
146@Sendable
147class D {
148  d: number = xx.b; // ERROR
149  foo () {
150    @sealed  // ERROR
151    class b {}
152  }
153}
154