• 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
16class A {
17    _field: int = 30;
18    static _sfield: int = 30;
19    get field(): int {
20        return this._field;
21    }
22
23    get sfield(): int {
24        return A._sfield;
25    }
26}
27
28set field(this: A, f: int) {
29    this._field = f;
30}
31
32set sfield(this: A, f: int) {
33    A._sfield = f;
34}
35
36function main(): void {
37    let obj: A = new A();
38    assertEQ(obj.field, 30);
39    obj.field = 1;
40    assertEQ(obj.field, 1);
41    obj.field++;
42    assertEQ(obj.field, 2);
43    ++obj.field;
44    assertEQ(obj.field, 3);
45    new A().sfield = 30;
46    assertEQ(new A().sfield, 30);
47    new A().sfield = 1;
48    assertEQ(new A().sfield, 1);
49    new A().sfield++;
50    assertEQ(new A().sfield, 2);
51    ++new A().sfield;
52    assertEQ(new A().sfield, 3);
53}
54