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 Base { 17 f: int 18} 19 20class InnerValue { 21 v: int 22} 23 24class C extends Base { 25 x: Int = 5 26 s: String = "" 27 iv: InnerValue = {} 28} 29 30function returnC(): C { 31 return {x: 99, f: 44, s: "qq", iv: {v: 77}} // return statement 32} 33 34function test(c: int, f: int, x: int, s: String, ivv: int) {} // should not prevent calling the next fun 35function test(c: C, f: int, x: int, s: String, ivv: int) { 36 assert c.f == f 37 assert c.x == x 38 assert c.s == s 39 assert c.iv.v == ivv 40} 41 42function main(): int { 43 let c: C = { // variable definition 44 "x": 7, 45 s: "sss", 46 }; 47 test(c, 0, 7, "sss", 0) 48 49 let c2 = { // as construction 50 f: 4, 51 s: "qq" 52 } as C; 53 test(c2, 4, 5, "qq", 0) 54 55 c = {f: 5, s: "zzz"} // assignment 56 test(c, 5, 5, "zzz", 0) 57 58 test({ // function argument 59 f: 3, 60 x: 8, 61 s: "uhuh", 62 iv: { // object literal field 63 v: 55 64 }}, 3, 8, "uhuh", 55) 65 66 test(returnC(), 44, 99, "qq", 77) 67 68 let ca: C[] = [{f: 42, s: "first"}, {f: 128, s: "second"}] // array elements 69 test(ca[1], 128, 5, "second", 0) 70 71 return 0 72} 73