1/* 2 * Copyright (c) 2024-2025 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 16function foo(param? : Object) 17{ 18 for (let i? of "blablabla") { } 19} 20 21function foo(b : int, a : int = 10, c : int = 15) : int 22{ 23 return a + b; 24} 25 26class Door { 27 private _width: int; 28 native get width(): int { 29 return this._width; 30 } 31} 32 33abstract class A{ 34 abstract constructor(val: int); 35}; 36 37let a: (c: int, b: int) => char rethrows; 38 39function foo(undefined int) { return 1} 40 41type 123 = int; 42 43type null = byte; 44 45type this = Object; 46 47const x; 48 49function f(a): void {} 50 51function foo(...q: int[], ...p: int[]): int { 52 return q.length + p.length; 53} 54 55function foo(...p: Object): Object { 56 return new Object(); 57} 58 59function foo(...p: int): int { 60 return 1; 61} 62 63function foo(a: int, ...p): int { 64 return a; 65} 66 67class A { 68 class B { 69 public x: int; 70 } 71} 72 73class A { 74 private interface I { fee(): int } 75} 76 77class B implements A.I { 78 public override fee(): int { 79 return 1; 80 } 81} 82 83class A { 84 class B { 85 i: int = 1; 86 } 87 getInner(): B { 88 return new B(); 89 } 90} 91 92class A { 93 class B { 94 foo(): int { 95 return 1; 96 } 97 } 98 getInner(): B { 99 return new B(); 100 } 101} 102 103function foo(... a: byte): void {} 104native function foo(... b: byte): long; 105 106function min(v: double, u: double): double { 107 assertTrue(false) 108 return v < u ? v : u; 109} 110 111class D1 { 112 internal getValue(): int { return 1 } 113} 114 115function foo<T, U>(a: T, case: U): T { 116 return a; 117} 118 119function foo<T, U>(a: T, case: U): T { 120 return a; 121} 122 123let ,abc = 0; 124 125declare async function foo(): Promise<void> 126 127declare function addResult(): number; 128 129function main(): void { 130 try { 131 throw new Exception(); 132 } catch () { 133 //Do something. 134 } 135 try { 136 throw new Exception(); 137 } catch (e = 0) { 138 //Do something. 139 } 140 141 assertTrue(foo(), undefined); 142 143 f(0); 144 145 let a10: A = new A(); 146 assertTrue(a10.getInner().i == 2); // #22840 assertEQ incorrect check types of operands 147 148 let instance_A: A = new A(2, 3); 149 let instanc_A: A = new A(2); 150 151 let instance0: D0 = new D0(); 152 instance0.x; 153 154 let instance1: D1 = new D1(); 155 instance1.getValue(); 156 157 let b: A = new A(); 158 assertTrue(b.getInner().foo() == 1); // #22840 assertEQ incorrect check types of operands 159 160 min(1.0, 1.0) 161 let let = 0; 162 let const = 0; 163 let new = 0; 164 foo<Long, Boolean>(new Long(), new Boolean(true)) 165 foo<Long, Boolean>(new Long(), new Boolean(true)) 166 f(); 167} 168 169/* @@? 18:14 Error SyntaxError: Optional variable is not allowed in for of statements. */ 170/* @@? 28:29 Error TypeError: Native, Abstract and Declare methods cannot have body. */ 171/* @@? 34:14 Error SyntaxError: The modifier for a constructor should be limited to access modifiers (private, internal, protected, public), and 'native' modifiers. */ 172/* @@? 37:41 Error SyntaxError: Only 'throws' can be used with function types. */ 173/* @@? 39:14 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ 174/* @@? 39:14 Error SyntaxError: Unexpected token, expected ',' or ')'. */ 175/* @@? 39:14 Error SyntaxError: Unexpected token, expected an identifier. */ 176/* @@? 39:24 Error SyntaxError: Unexpected token 'int'. */ 177/* @@? 39:27 Error SyntaxError: Unexpected token ')'. */ 178/* @@? 39:29 Error SyntaxError: Unexpected token '{'. */ 179/* @@? 39:31 Error SyntaxError: return keyword should be used in function body. */ 180/* @@? 39:38 Error TypeError: All return statements in the function should be empty or have a value. */ 181/* @@? 41:1 Error TypeError: Unresolved reference type */ 182/* @@? 41:6 Error SyntaxError: Unexpected token '123'. */ 183/* @@? 41:6 Error TypeError: Invalid left-hand side of assignment expression */ 184/* @@? 41:10 Error SyntaxError: Invalid left-hand side in assignment expression. */ 185/* @@? 41:12 Error SyntaxError: Unexpected token 'int'. */ 186/* @@? 43:6 Error SyntaxError: Unexpected token 'null'. */ 187/* @@? 43:6 Error TypeError: Invalid left-hand side of assignment expression */ 188/* @@? 43:11 Error SyntaxError: Invalid left-hand side in assignment expression. */ 189/* @@? 43:13 Error SyntaxError: Unexpected token 'byte'. */ 190/* @@? 45:6 Error SyntaxError: Unexpected token 'this'. */ 191/* @@? 45:6 Error TypeError: Invalid left-hand side of assignment expression */ 192/* @@? 45:6 Error TypeError: Cannot reference 'this' in this context. */ 193/* @@? 45:11 Error SyntaxError: Invalid left-hand side in assignment expression. */ 194/* @@? 47:8 Error SyntaxError: Variable must be initialized or it's type must be declared. */ 195/* @@? 47:8 Error TypeError: Missing initializer in const declaration */ 196/* @@? 49:13 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ 197/* @@? 51:25 Error SyntaxError: Rest parameter must be the last formal parameter. */ 198/* @@? 51:27 Error SyntaxError: Unexpected token '...'. */ 199/* @@? 51:30 Error SyntaxError: Unexpected token 'p'. */ 200/* @@? 51:33 Error SyntaxError: Label must be followed by a loop statement. */ 201/* @@? 51:38 Error SyntaxError: Unexpected token ')'. */ 202/* @@? 51:39 Error SyntaxError: Unexpected token ':'. */ 203/* @@? 51:41 Error SyntaxError: Unexpected token 'int'. */ 204/* @@? 51:45 Error SyntaxError: Unexpected token '{'. */ 205/* @@? 52:5 Error SyntaxError: return keyword should be used in function body. */ 206/* @@? 52:12 Error TypeError: All return statements in the function should be empty or have a value. */ 207/* @@? 52:12 Error TypeError: Unresolved reference q */ 208/* @@? 52:23 Error TypeError: Unresolved reference p */ 209/* @@? 55:14 Error SyntaxError: Rest parameter should be either array or tuple type. */ 210/* @@? 63:26 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ 211/* @@? 67:7 Error TypeError: Merging declarations is not supported, please keep all definitions of classes, interfaces and enums compact in the codebase! */ 212/* @@? 67:7 Error TypeError: Variable 'A' has already been declared. */ 213/* @@? 68:3 Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ 214/* @@? 73:7 Error TypeError: Merging declarations is not supported, please keep all definitions of classes, interfaces and enums compact in the codebase! */ 215/* @@? 73:7 Error TypeError: Variable 'A' has already been declared. */ 216/* @@? 74:11 Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ 217/* @@? 77:20 Error TypeError: Interface expected here. */ 218/* @@? 77:22 Error TypeError: 'I' type does not exist. */ 219/* @@? 78:22 Error TypeError: Method fee(): int in B not overriding any method */ 220/* @@? 83:7 Error TypeError: Merging declarations is not supported, please keep all definitions of classes, interfaces and enums compact in the codebase! */ 221/* @@? 83:7 Error TypeError: Variable 'A' has already been declared. */ 222/* @@? 84:3 Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ 223/* @@? 92:7 Error TypeError: Variable 'A' has already been declared. */ 224/* @@? 92:7 Error TypeError: Merging declarations is not supported, please keep all definitions of classes, interfaces and enums compact in the codebase! */ 225/* @@? 93:3 Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ 226/* @@? 115:26 Error SyntaxError: Unexpected token, expected an identifier. */ 227/* @@? 115:26 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ 228/* @@? 115:26 Error SyntaxError: Unexpected token, expected ',' or ')'. */ 229/* @@? 115:26 Error SyntaxError: Unexpected token 'case'. */ 230/* @@? 115:30 Error SyntaxError: Unexpected token ':'. */ 231/* @@? 115:32 Error SyntaxError: Unexpected token 'U'. */ 232/* @@? 115:32 Error TypeError: Unresolved reference U */ 233/* @@? 115:33 Error SyntaxError: Unexpected token ')'. */ 234/* @@? 115:34 Error SyntaxError: Unexpected token ':'. */ 235/* @@? 115:36 Error SyntaxError: Unexpected token 'T'. */ 236/* @@? 115:36 Error TypeError: Unresolved reference T */ 237/* @@? 115:38 Error SyntaxError: Unexpected token '{'. */ 238/* @@? 116:5 Error SyntaxError: return keyword should be used in function body. */ 239/* @@? 116:12 Error TypeError: All return statements in the function should be empty or have a value. */ 240/* @@? 119:26 Error SyntaxError: Unexpected token 'case'. */ 241/* @@? 119:26 Error SyntaxError: Unexpected token, expected an identifier. */ 242/* @@? 119:26 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ 243/* @@? 119:26 Error SyntaxError: Unexpected token, expected ',' or ')'. */ 244/* @@? 119:30 Error SyntaxError: Unexpected token ':'. */ 245/* @@? 119:32 Error SyntaxError: Unexpected token 'U'. */ 246/* @@? 119:33 Error SyntaxError: Unexpected token ')'. */ 247/* @@? 119:34 Error SyntaxError: Unexpected token ':'. */ 248/* @@? 119:36 Error SyntaxError: Unexpected token 'T'. */ 249/* @@? 119:38 Error SyntaxError: Unexpected token '{'. */ 250/* @@? 120:5 Error SyntaxError: return keyword should be used in function body. */ 251/* @@? 120:12 Error TypeError: All return statements in the function should be empty or have a value. */ 252/* @@? 123:5 Error SyntaxError: Identifier expected, got ','. */ 253/* @@? 123:6 Error SyntaxError: Variable must be initialized or it's type must be declared. */ 254/* @@? 123:6 Error SyntaxError: Unexpected token 'abc'. */ 255/* @@? 123:6 Error SyntaxError: Variable must be initialized or it's type must be declared. */ 256/* @@? 123:6 Error TypeError: Unresolved reference abc */ 257/* @@? 127:1 Error SyntaxError: The modifier async cannot be used in an ambient context. */ 258/* @@? 132:14 Error SyntaxError: Unexpected token, expected an identifier. */ 259/* @@? 137:16 Error SyntaxError: Expected '{', got '='. */ 260/* @@? 137:16 Error SyntaxError: Unexpected token '='. */ 261/* @@? 137:16 Error SyntaxError: Expected '{', got '='. */ 262/* @@? 137:16 Error SyntaxError: Catch clause variable cannot have an initializer. */ 263/* @@? 137:16 Error SyntaxError: Expected ')', got '='. */ 264/* @@? 137:18 Error SyntaxError: Unexpected token '0'. */ 265/* @@? 137:19 Error SyntaxError: Unexpected token ')'. */ 266/* @@? 137:21 Error SyntaxError: Unexpected token '{'. */ 267/* @@? 141:16 Error TypeError: This expression is not callable. */ 268/* @@? 145:18 Error TypeError: A is abstract therefore cannot be instantiated. */ 269/* @@? 146:16 Error TypeError: Bad operand type, the types of the operands must be numeric, same enumeration, or boolean type. */ 270/* @@? 148:25 Error TypeError: A is abstract therefore cannot be instantiated. */ 271/* @@? 149:24 Error TypeError: A is abstract therefore cannot be instantiated. */ 272/* @@? 151:20 Error TypeError: Cannot find type 'D0'. */ 273/* @@? 151:29 Error TypeError: Cannot find type 'D0'. */ 274/* @@? 157:16 Error TypeError: A is abstract therefore cannot be instantiated. */ 275/* @@? 158:16 Error TypeError: Bad operand type, the types of the operands must be numeric, same enumeration, or boolean type. */ 276/* @@? 161:9 Error SyntaxError: Identifier expected, got 'let'. */ 277/* @@? 162:9 Error SyntaxError: Identifier expected, got 'const'. */ 278/* @@? 163:9 Error SyntaxError: Identifier expected, got 'new'. */ 279/* @@? 164:5 Error TypeError: This expression is not callable. */ 280/* @@? 165:5 Error TypeError: This expression is not callable. */ 281/* @@? 166:5 Error TypeError: Expected 1 arguments, got 0. */ 282/* @@? 166:5 Error TypeError: No matching call signature */ 283/* @@? 284:1 Error SyntaxError: Expected '}', got 'end of stream'. */ 284