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
16function check1() {
17    let a8 : string|Int[] = "abc"
18    let str = "";
19    for (let character : Char|Int of a8) {
20        if (character instanceof Char) {
21            str += character;
22        }
23    }
24
25    assert(str == "abc");
26}
27
28function check2() {
29    let a9 : string|Int[] = [1,2] as Int[]
30    let sum = 0;
31    for (let val : Char|Int of a9) {
32        let b9 = val
33        if (b9 instanceof Int) {
34            sum += b9;
35        }
36    }
37
38    assert(sum == 3);
39}
40
41function fooStr() : string|Int[] {
42    let a : string|Int[] = "abc";
43    return a;
44}
45
46function check3() {
47    let a8 : string|Int[] = fooStr();
48    let target : Char|Int = 0;
49    for (let character : Char|Int of a8) {
50        target = character;
51    }
52
53    assert(target instanceof Char);
54}
55
56function fooInt() : string|Int[] {
57    let a : string|Int[] = [1,2] as Int[];
58    return a;
59}
60
61function check4() {
62    let a8 : string|Int[] = fooInt();
63    let target : Char|Int = 0;
64    for (let val : Char|Int of a8) {
65        target = val;
66    }
67
68    assert((target instanceof Int) && (target == 2));
69}
70
71function main() {
72    check1();
73    check2();
74    check3();
75    check4();
76}
77