1/** 2 * Copyright (c) 2023-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 16interface I { 17 self(): I; 18 fn(): Object; 19 fn2(): Object; 20 fn3(): Object; 21 fn4(): Object; 22 fn5(): Object[]; 23} 24 25class A implements I { 26 public x: int = 42; 27 override self(): A { return this; } 28 override fn(): String { return ""; } 29 override fn2(): Object[] { return [new Object()]; } 30 override fn3(): int[] { return [0]; } 31 override fn4(): int[][] { return [[0]]; } 32 override fn5(): String[] { return [""]; } 33} 34 35 36function main(): void { 37 let a = new A(); 38 assert a.self().x == 42; 39 assert a.fn() == ""; 40 assert a.fn2().length == 1; 41 assert a.fn3()[0] == 0; 42 assert a.fn4()[0][0] == 0; 43 assert a.fn5()[0] == ""; 44 45 // let i: I = a; 46 // assert i.self() instanceof A; 47 // assert (i.fn() as String) == ""; 48 // assert (i.fn2() as Object[])[0] == new Object(); 49 // assert (i.fn3() as int[])[0] == 0; 50 // assert (i.fn4() as String[])[0] == ""; 51} 52 53 54