From c9fce7092de287a3ef8b20bf6b546bc953e4d115 Mon Sep 17 00:00:00 2001 From: ertugrulfarukpiskin Date: Fri, 18 Jul 2025 11:40:41 +0300 Subject: [PATCH] Constrained Type Param Crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICKLXI Description: Constrained Type Params on Lambdas Give Crash Signed-off-by: ertugrulfarukpiskin --- ets2panda/checker/ets/object.cpp | 2 +- .../compiler/ets/generic_lambda_constraint.ets | 18 ++++++++++++++++++ .../ets/generic_lambda_constraint2.ets | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/generic_lambda_constraint.ets create mode 100644 ets2panda/test/ast/compiler/ets/generic_lambda_constraint2.ets diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 82f486c79e..3d476850c4 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -392,7 +392,7 @@ bool ETSChecker::CheckTypeParameterConstraint(ir::TSTypeParameter *param, Type2T void ETSChecker::SetUpTypeParameterConstraint(ir::TSTypeParameter *const param) { - ETSTypeParameter *const paramType = param->Name()->Variable()->TsType()->AsETSTypeParameter(); + ETSTypeParameter *const paramType = SetUpParameterType(param); auto const traverseReferenced = [this, scope = param->Parent()->AsTSTypeParameterDeclaration()->Scope()](ir::TypeNode *typeNode) { if (!typeNode->IsETSTypeReference()) { diff --git a/ets2panda/test/ast/compiler/ets/generic_lambda_constraint.ets b/ets2panda/test/ast/compiler/ets/generic_lambda_constraint.ets new file mode 100644 index 0000000000..05712b3324 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/generic_lambda_constraint.ets @@ -0,0 +1,18 @@ +/* + * 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 foo = (t: T, s: U) => {}; + +/* @@? 16:11 Error TypeError: Type '(t: T, s: U) => void' cannot be assigned to type '(t: T, s: U) => void' */ diff --git a/ets2panda/test/ast/compiler/ets/generic_lambda_constraint2.ets b/ets2panda/test/ast/compiler/ets/generic_lambda_constraint2.ets new file mode 100644 index 0000000000..68af871b31 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/generic_lambda_constraint2.ets @@ -0,0 +1,18 @@ +/* + * 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 foo = (t: T, s: U) => {}; + +/* @@? 16:11 Error TypeError: Type '(t: T, s: U) => void' cannot be assigned to type '(t: T, s: U) => void' */ -- Gitee