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 16class A { 17 foo(): int { 18 return 1; 19 } 20 21 final baz(): int { 22 return this.foo(); // virtual call expected 23 } 24} 25 26final class B extends A { 27 override foo(): int { 28 return 2; 29 } 30 31 bar(): int { 32 return super.foo(); // static call expected 33 } 34 35 virt(): int { 36 return super.baz(); 37 } 38} 39 40class F { 41 public readonly f: int; 42 43 constructor() { 44 this.f = 42; 45 } 46} 47 48final class G extends F { 49 50} 51 52final class H extends F { 53 constructor() { 54 55 } 56} 57 58final class I extends F { 59 constructor() { 60 super(); 61 } 62} 63 64function main(): void { 65 let bClass: B = new B(); 66 67 let a: int = bClass.foo(); 68 assert a == 2 69 70 let b: int = bClass.bar(); 71 assert b == 1 72 73 let c: int = bClass.virt(); 74 assert c == 2 75 76 const f: F = new F(); 77 assert f.f == 42; 78 79 const g: G = new G(); 80 assert g.f == 42; 81 82 const h: H = new H(); 83 assert h.f == 42; 84 85 const i: I = new I(); 86 assert i.f == 42; 87 88 let d_as_A: F = i; 89 assert d_as_A.f == 42; 90} 91