From c2301af84ba41a70561e41cc2d0d6451c882f27d Mon Sep 17 00:00:00 2001 From: shawn_hu_ls Date: Thu, 16 Mar 2023 11:04:39 +0800 Subject: [PATCH] Fix confused explicitly specified and mandatory `this` params Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I6NHMN?from=project-issue Signed-off-by: shawn_hu_ls --- es2panda/binder/scope.h | 3 +- es2panda/ir/base/scriptFunction.h | 3 +- .../functions/test-ts-function-3-expected.txt | 2 ++ .../functions/test-ts-function-3.ts | 29 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3.ts diff --git a/es2panda/binder/scope.h b/es2panda/binder/scope.h index d2bc3419d4..961499455e 100644 --- a/es2panda/binder/scope.h +++ b/es2panda/binder/scope.h @@ -514,9 +514,10 @@ public: bool AddBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, [[maybe_unused]] ScriptExtension extension) override; - void RemoveThisParam() + void RemoveThisParam(const std::string_view &thisParam) { params_.erase(params_.begin()); + bindings_.erase(thisParam); } friend class FunctionScope; diff --git a/es2panda/ir/base/scriptFunction.h b/es2panda/ir/base/scriptFunction.h index b610c74a50..b297306853 100644 --- a/es2panda/ir/base/scriptFunction.h +++ b/es2panda/ir/base/scriptFunction.h @@ -59,7 +59,8 @@ public: if (firstParam->IsIdentifier() && firstParam->AsIdentifier()->Name().Is(THIS_PARAM)) { thisParam_ = firstParam; params_.erase(params_.begin()); - scope_->ParamScope()->RemoveThisParam(); + scope_->ParamScope()->RemoveThisParam(THIS_PARAM); + scope_->Bindings().erase(THIS_PARAM); } } } diff --git a/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3-expected.txt b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3-expected.txt new file mode 100644 index 0000000000..fece8ea852 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3-expected.txt @@ -0,0 +1,2 @@ +Test +20 diff --git a/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3.ts b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3.ts new file mode 100644 index 0000000000..81311acd69 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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 Employee { + name : string + debug : (number) => void +} + +function dump(this : Employee, age : number) { + print(this.name) + print(age) +} + +let a : Employee = {name : "Test", debug : dump} +a.debug(20) + -- Gitee