1/* 2 * Copyright (c) 2021-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 public readonly a: int; 18 19 constructor() { 20 this.a = 42; 21 } 22} 23 24final class B extends A { 25 26} 27 28final class C extends A { 29 constructor() { 30 31 } 32} 33 34final class D extends A { 35 constructor() { 36 super(); 37 } 38} 39 40 41function main(): void { 42 const a: A = new A(); 43 assert a.a == 42; 44 45 const b: B = new B(); 46 assert b.a == 42; 47 48 const c: C = new C(); 49 assert c.a == 42; 50 51 const d: D = new D(); 52 assert d.a == 42; 53 54 let d_as_A: A = d; 55 assert d_as_A.a == 42; 56} 57