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
16class A {
17    data: string[] = ['a', 'b', 'c'];
18    $_iterator() {
19      return new B();
20    }
21}
22
23class B {}
24
25class CIterator implements Iterator<string> {
26    index = 0;
27    base: A;
28    constructor (base: A) {
29        this.base = base;
30    }
31    next(): IteratorResult<string> {
32        if (this.index >= this.base.data.length) {
33            return {
34                done: true,
35                value: undefined
36            }
37        }
38        return {
39          done: this.index >= this.base.data.length,
40          value: this.base.data[this.index++]
41        }
42    }
43}
44
45function main(): void {
46    let res = "";
47    let a = new A();
48    for (let x of a) res += x;
49    assert(res == "abc");
50}
51
52/* @@? 48:19 Error TypeError: Iterator method must return an object which implements Iterator<T>  */
53/* @@? 48:19 Error TypeError: 'For-of' statement source expression is not of iterable type. */
54/* @@? 18:15 Error TypeError: The return type of '$_iterator' must be a type that implements Iterator interface.  */