diff --git a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp index e24fe2ea47447cb4b85a8a6b508f29360ce798ce..8a74f933d70cee25b585324514e83004dec89c17 100644 --- a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp +++ b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp @@ -118,6 +118,7 @@ static void PopulateCtorArgumentsFromMap(public_lib::Context *ctx, ir::ObjectExp ArenaVector &ctorArguments, std::map &ctorArgumentsMap) { + auto checker = ctx->checker->AsETSChecker(); if (ctorArgumentsMap.empty()) { return; } @@ -126,11 +127,13 @@ static void PopulateCtorArgumentsFromMap(public_lib::Context *ctx, ir::ObjectExp for (auto param : classType->ConstructSignatures().front()->Params()) { auto ctorArgument = ctorArgumentsMap[param->Declaration()->Name()]; - if (ctorArgument == nullptr && objExpr->PreferredType()->AsETSObjectType()->IsPartial()) { - ctorArguments.push_back(allocator->New()); + if (ctorArgument != nullptr) { + ctorArguments.push_back(ctorArgument); continue; } - ctorArguments.push_back(ctorArgument); + if (checker->Relation()->IsSupertypeOf(param->TsType(), checker->GlobalETSUndefinedType())) { + ctorArguments.push_back(allocator->New()); + } } } diff --git a/ets2panda/compiler/lowering/ets/optionalArgumentsLowering.cpp b/ets2panda/compiler/lowering/ets/optionalArgumentsLowering.cpp index 701623fc5240c7e27b072978287c06d0c7907a47..562ae7cc85c02831ecd32df22133238dcd0881ce 100644 --- a/ets2panda/compiler/lowering/ets/optionalArgumentsLowering.cpp +++ b/ets2panda/compiler/lowering/ets/optionalArgumentsLowering.cpp @@ -37,8 +37,8 @@ static void TransformArgumentsForTrailingLambda(public_lib::Context *ctx, ir::Ca static void TransformArguments(public_lib::Context *ctx, ir::Expression *callLike, checker::Signature *signature, ArenaVector &arguments) { - if (signature->ArgCount() < arguments.size()) { - ES2PANDA_ASSERT(signature->HasRestParameter()); + if (signature == nullptr || signature->ArgCount() < arguments.size()) { + ES2PANDA_ASSERT(signature == nullptr || signature->HasRestParameter()); return; } ES2PANDA_ASSERT(signature->ArgCount() >= signature->MinArgCount()); diff --git a/ets2panda/compiler/lowering/ets/spreadLowering.cpp b/ets2panda/compiler/lowering/ets/spreadLowering.cpp index 1c2f4241cfe1d3dc64d53e299a1d4cf8b96c6e17..4edf4ef0898da0d25f53e11bbb4ad861ad019fe6 100644 --- a/ets2panda/compiler/lowering/ets/spreadLowering.cpp +++ b/ets2panda/compiler/lowering/ets/spreadLowering.cpp @@ -368,10 +368,15 @@ bool SpreadConstructionPhase::PerformForModule(public_lib::Context *ctx, parser: varbinder::LexicalScope::Enter(checker->VarBinder(), NearestScope(node)); const auto *const arrayExprType = node->AsArrayExpression()->TsType(); - ir::BlockExpression *blockExpression = - arrayExprType->IsETSArrayType() || arrayExprType->IsETSResizableArrayType() - ? CreateLoweredExpressionForArray(ctx, node->AsArrayExpression()) - : CreateLoweredExpressionForTuple(ctx, node->AsArrayExpression()); + ir::BlockExpression *blockExpression = nullptr; + if (arrayExprType->IsETSArrayType() || arrayExprType->IsETSResizableArrayType()) { + blockExpression = CreateLoweredExpressionForArray(ctx, node->AsArrayExpression()); + } else if (arrayExprType->IsETSTupleType()) { + blockExpression = CreateLoweredExpressionForTuple(ctx, node->AsArrayExpression()); + } else { + checker->LogError(diagnostic::SPREAD_OF_INVALID_TYPE, {arrayExprType}, node->Start()); + return node; + } blockExpression->SetParent(node->Parent()); // NOTE: this blockExpression is a kind of formatted-dummy code, which is invisible to users, diff --git a/ets2panda/test/ast/parser/ets/objectliteral_optinal_parameter.ets b/ets2panda/test/ast/parser/ets/objectliteral_optinal_parameter.ets new file mode 100644 index 0000000000000000000000000000000000000000..77ea15700aa2c85ccefd4d868d88be99cba0c442 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/objectliteral_optinal_parameter.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface UserPreferences { + readonly importModuleSpecifierPreference: "shortest" | "project-relative" | "relative" | "non-relative"; + readonly importModuleSpecifierEnding?: "minimal" | "index" | "js"; + readonly jsxAttributeCompletionStyle?: "auto" | "braces" | "none"; +} + +class verify{ + static importFixModuleSpecifiers(marker: string, moduleSpecifiers: string[], options?: UserPreferences): void{}; +} +verify.importFixModuleSpecifiers("", ["#internals/example"], { importModuleSpecifierEnding: "js" }); + +/* @@? 1:3 Error TypeError: Expected 3 arguments, got 2. */ +/* @@? 1:3 Error TypeError: No matching construct signature for objectliteral_optinal_parameter.objectliteral_optinal_parameter$UserPreferences$ObjectLiteral("js", undefined) */ \ No newline at end of file diff --git a/ets2panda/test/ast/parser/ets/override_lambda_field.ets b/ets2panda/test/ast/parser/ets/override_lambda_field.ets new file mode 100644 index 0000000000000000000000000000000000000000..0906af1f82ccbe2865a7323a069af95cd8687ce8 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/override_lambda_field.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class a{ + /* @@ label1 */foo111:()=>string; + static /* @@ label2 */foo222:()=>string; +} + +class b extends a{ + /* @@ label3 */foo111:()=>string; + static /* @@ label4 */foo222:()=>string; +} + +/* @@@ label1 Error TypeError: Property 'foo111' might not have been initialized. */ +/* @@@ label2 Error TypeError: Property 'foo222' might not have been initialized. */ +/* @@@ label3 Error TypeError: Property 'foo111' might not have been initialized. */ +/* @@@ label4 Error TypeError: Property 'foo222' might not have been initialized. */ diff --git a/ets2panda/test/ast/parser/ets/spread_errortype.ets b/ets2panda/test/ast/parser/ets/spread_errortype.ets new file mode 100644 index 0000000000000000000000000000000000000000..804f1f6296933283697a8659c1ab085df45557f3 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/spread_errortype.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let tup: [number, number, number] = [1, 2, 3, 4]; +let SRr2:[number, number, number] = /* @@ label */[1, 2, 3, ...tup]; + +/* @@@ label Error TypeError: Spread expression can be applied only to array or tuple type, but '*ERROR_TYPE*' is provided */ diff --git a/ets2panda/test/runtime/ets/objectliteral_optinal_parameter.ets b/ets2panda/test/runtime/ets/objectliteral_optinal_parameter.ets new file mode 100644 index 0000000000000000000000000000000000000000..0e9994bac365acb37c25fd37e2dc2be3a5e5145b --- /dev/null +++ b/ets2panda/test/runtime/ets/objectliteral_optinal_parameter.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface UserPreferences { + readonly importModuleSpecifierPreference?: "shortest" | "project-relative" | "relative" | "non-relative"; + readonly importModuleSpecifierEnding?: "minimal" | "index" | "js"; + readonly jsxAttributeCompletionStyle?: "auto" | "braces" | "none"; +} + +class Verify { + static field?: UserPreferences = {} + static importFixModuleSpecifiers(marker: string, moduleSpecifiers: string[], options?: UserPreferences): void { + Verify.field = options; + }; +} + +function main() { + Verify.importFixModuleSpecifiers("", ["#internals/example"], { importModuleSpecifierEnding: "js" }); + assertEQ(Verify.field!.importModuleSpecifierPreference,undefined) + assertEQ(Verify.field!.importModuleSpecifierEnding,"js") + assertEQ(Verify.field!.jsxAttributeCompletionStyle,undefined) +}