diff --git a/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp b/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp index 5f71a7becde5865645818d97b9dcffbbf2035a3b..30e0f5d323ee1fbb046406ccb7a7dc06cba0c277 100644 --- a/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp +++ b/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp @@ -286,8 +286,6 @@ static void ProcessGlobalFunctionDefinition(ir::MethodDefinition *method, public if (param->Initializer() == nullptr) { ES2PANDA_ASSERT(param->IsOptional()); init = allocator->New(); - } else if (param->Initializer()->IsArrowFunctionExpression()) { - init = param->Initializer(); } else { init = param->Initializer()->Clone(allocator, nullptr)->AsExpression(); } diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt index 37be6b553bc36d7acd28df82edde91daead7b03b..0248d709634cbd1b26d41d905c87892b3e02c2ef 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt @@ -2477,8 +2477,8 @@ "program": "module.ets" }, "end": { - "line": 45, - "column": 7, + "line": 43, + "column": 44, "program": "module.ets" } } @@ -2490,8 +2490,8 @@ "program": "module.ets" }, "end": { - "line": 45, - "column": 7, + "line": 43, + "column": 44, "program": "module.ets" } } @@ -2707,8 +2707,8 @@ "program": "module.ets" }, "end": { - "line": 49, - "column": 7, + "line": 47, + "column": 30, "program": "module.ets" } } @@ -2762,7 +2762,7 @@ }, "end": { "line": 49, - "column": 46, + "column": 35, "program": "module.ets" } } @@ -2775,7 +2775,7 @@ }, "end": { "line": 49, - "column": 46, + "column": 35, "program": "module.ets" } } @@ -2812,7 +2812,7 @@ }, "end": { "line": 49, - "column": 50, + "column": 49, "program": "module.ets" } } @@ -2825,7 +2825,7 @@ }, "end": { "line": 49, - "column": 50, + "column": 49, "program": "module.ets" } } @@ -3060,7 +3060,7 @@ }, "end": { "line": 51, - "column": 17, + "column": 16, "program": "module.ets" } } @@ -3073,7 +3073,7 @@ }, "end": { "line": 51, - "column": 17, + "column": 16, "program": "module.ets" } } @@ -3086,7 +3086,7 @@ }, "end": { "line": 51, - "column": 17, + "column": 16, "program": "module.ets" } } @@ -3099,7 +3099,7 @@ }, "end": { "line": 51, - "column": 17, + "column": 16, "program": "module.ets" } } @@ -3188,7 +3188,7 @@ }, "end": { "line": 51, - "column": 17, + "column": 16, "program": "module.ets" } } @@ -3201,7 +3201,7 @@ }, "end": { "line": 51, - "column": 17, + "column": 16, "program": "module.ets" } } @@ -3242,7 +3242,7 @@ }, "end": { "line": 51, - "column": 17, + "column": 16, "program": "module.ets" } } @@ -3255,7 +3255,7 @@ }, "end": { "line": 51, - "column": 17, + "column": 16, "program": "module.ets" } } @@ -3270,7 +3270,7 @@ }, "end": { "line": 51, - "column": 17, + "column": 16, "program": "module.ets" } } @@ -3285,7 +3285,7 @@ }, "end": { "line": 51, - "column": 17, + "column": 16, "program": "module.ets" } } @@ -3367,8 +3367,8 @@ "program": "module.ets" }, "end": { - "line": 53, - "column": 2, + "line": 52, + "column": 15, "program": "module.ets" } } @@ -3380,8 +3380,8 @@ "program": "module.ets" }, "end": { - "line": 53, - "column": 2, + "line": 52, + "column": 15, "program": "module.ets" } } @@ -3393,8 +3393,8 @@ "program": "module.ets" }, "end": { - "line": 53, - "column": 2, + "line": 52, + "column": 15, "program": "module.ets" } } @@ -3406,8 +3406,8 @@ "program": "module.ets" }, "end": { - "line": 53, - "column": 2, + "line": 52, + "column": 15, "program": "module.ets" } } @@ -3495,8 +3495,8 @@ "program": "module.ets" }, "end": { - "line": 53, - "column": 2, + "line": 52, + "column": 15, "program": "module.ets" } } @@ -3508,8 +3508,8 @@ "program": "module.ets" }, "end": { - "line": 53, - "column": 2, + "line": 52, + "column": 15, "program": "module.ets" } } @@ -3549,8 +3549,8 @@ "program": "module.ets" }, "end": { - "line": 53, - "column": 2, + "line": 52, + "column": 15, "program": "module.ets" } } @@ -3562,8 +3562,8 @@ "program": "module.ets" }, "end": { - "line": 53, - "column": 2, + "line": 52, + "column": 15, "program": "module.ets" } } @@ -3577,8 +3577,8 @@ "program": "module.ets" }, "end": { - "line": 53, - "column": 2, + "line": 52, + "column": 15, "program": "module.ets" } } @@ -3592,8 +3592,8 @@ "program": "module.ets" }, "end": { - "line": 53, - "column": 2, + "line": 52, + "column": 15, "program": "module.ets" } } @@ -3661,7 +3661,7 @@ }, "end": { "line": 50, - "column": 41, + "column": 39, "program": "module.ets" } } @@ -3674,7 +3674,7 @@ }, "end": { "line": 50, - "column": 41, + "column": 39, "program": "module.ets" } } @@ -3687,7 +3687,7 @@ }, "end": { "line": 50, - "column": 41, + "column": 39, "program": "module.ets" } } @@ -3700,8 +3700,8 @@ "program": "module.ets" }, "end": { - "line": 55, - "column": 7, + "line": 53, + "column": 2, "program": "module.ets" } } @@ -3755,7 +3755,7 @@ }, "end": { "line": 59, - "column": 45, + "column": 43, "program": "module.ets" } } @@ -3768,7 +3768,7 @@ }, "end": { "line": 59, - "column": 45, + "column": 43, "program": "module.ets" } } @@ -3828,8 +3828,8 @@ "program": "module.ets" }, "end": { - "line": 61, - "column": 2, + "line": 60, + "column": 19, "program": "module.ets" } } @@ -3841,8 +3841,8 @@ "program": "module.ets" }, "end": { - "line": 61, - "column": 2, + "line": 60, + "column": 19, "program": "module.ets" } } @@ -3856,8 +3856,8 @@ "program": "module.ets" }, "end": { - "line": 61, - "column": 2, + "line": 60, + "column": 19, "program": "module.ets" } } @@ -4754,8 +4754,8 @@ "program": "module.ets" }, "end": { - "line": 59, - "column": 1, + "line": 57, + "column": 2, "program": "module.ets" } } @@ -4767,8 +4767,8 @@ "program": "module.ets" }, "end": { - "line": 59, - "column": 1, + "line": 57, + "column": 2, "program": "module.ets" } } diff --git a/ets2panda/test/runtime/ets/lambdaAsConstructorParamWithDefaultValue.ets b/ets2panda/test/runtime/ets/lambdaAsConstructorParamWithDefaultValue.ets new file mode 100644 index 0000000000000000000000000000000000000000..2138989e9c2941bff4718c8537dd5bf6faeac4be --- /dev/null +++ b/ets2panda/test/runtime/ets/lambdaAsConstructorParamWithDefaultValue.ets @@ -0,0 +1,52 @@ +/* + * 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 { + p: undefined | int | () => int + q: string | ()=>string + constructor( + p?: int | () => int, + q: string | ()=>string = ()=>"Hello!" + ) { + this.p = p + this.q = q + } +} + +function main() { + let a = new A() + let ap = a.p + arktest.assertEQ(ap, undefined) + let aq = a.q + arktest.assertEQ(aq instanceof string ? "" : aq(), "Hello!") + + a = new A(12) + ap = a.p + arktest.assertEQ(ap, 12) + aq = a.q + arktest.assertEQ(aq instanceof string ? "" : aq(), "Hello!") + + a = new A(12, "BYE!") + ap = a.p + arktest.assertEQ(ap, 12) + aq = a.q + arktest.assertEQ(aq instanceof string ? aq : "", "BYE!") + + a = new A(():int=>12, ():string=>"HI!") + ap = a.p + arktest.assertEQ(ap instanceof int ? 0 : ap!(), 12) + aq = a.q + arktest.assertEQ(aq instanceof string ? "" : aq(), "HI!") +}