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 C { 17 data: string[] = ['a', 'b', 'c'] 18 static $_iterator() { 19 return new CIterator(new C()) 20 } 21} 22class CIterator implements Iterator<string> { 23 index = 0 24 base: C 25 constructor (base: C) { 26 this.base = base 27 } 28 next(): IteratorResult<string> { 29 return { 30 done: this.index >= this.base.data.length, 31 value: this.index >= this.base.data.length ? undefined : this.base.data[this.index++] 32 } 33 } 34} 35 36function main(): int { 37 let c = new C() 38 let res = '' 39 for (let x of c) { 40 res += x 41 } 42 if (res != 'abc') return 1 43 return 0 44} 45 46/* @@? 39:17 Error TypeError: '$_iterator' is a static property of 'C' */ 47/* @@? 39:17 Error TypeError: 'For-of' statement source expression is not of iterable type. */ 48