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 { memb: number = 2; } 17class B { memb: number = 6; } 18class C { memb: A|B = new A(); } 19 20function bar(a0: A | B): void { 21 a0.memb = 50; 22} 23 24function foo(arr: Int8Array | Int16Array): void { 25 let len = arr.length 26 assert len == 42; 27} 28 29function main() { 30 let buffer: ArrayBuffer = new ArrayBuffer(42); 31 let byteArr: Int8Array= new Int8Array(buffer) 32 foo(byteArr); 33 assert byteArr.length == 42; 34 35 let ab: A|B = new A(); 36 bar(ab); 37 assert ab.memb == 50 38 39 let cClass: C = new C(); 40 cClass.memb = new B(); 41 assert cClass.memb.memb == 6; 42} 43