From 374f42c12488a3b3e93482f62ece4751201325b0 Mon Sep 17 00:00:00 2001 From: huyunhui Date: Sat, 20 Apr 2024 15:32:52 +0800 Subject: [PATCH] Fix the compilation of call expression with chain expression as callee Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9IB6D Signed-off-by: huyunhui Change-Id: I715f53605a0aa5af11304412d2fac8b55dbb9601 --- es2panda/ir/expressions/callExpression.cpp | 4 ++-- ...th-chain-expression-as-callee-expected.txt | 1 + ...ression-with-chain-expression-as-callee.js | 22 +++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee-expected.txt create mode 100644 es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee.js diff --git a/es2panda/ir/expressions/callExpression.cpp b/es2panda/ir/expressions/callExpression.cpp index 0956850bfc..2d3370bb80 100644 --- a/es2panda/ir/expressions/callExpression.cpp +++ b/es2panda/ir/expressions/callExpression.cpp @@ -65,7 +65,7 @@ compiler::VReg CallExpression::CreateSpreadArguments(compiler::PandaGen *pg) con void CallExpression::Compile(compiler::PandaGen *pg) const { - ir::Expression *realCallee = callee_; + const ir::Expression *realCallee = callee_; while (realCallee->IsTSNonNullExpression() || realCallee->IsTSAsExpression() || realCallee->IsTSTypeAssertion()) { if (realCallee->IsTSNonNullExpression()) { realCallee = realCallee->AsTSNonNullExpression()->Expr(); @@ -146,7 +146,7 @@ void CallExpression::Compile(compiler::PandaGen *pg) const compiler::RegScope mrs(pg); realCallee->AsMemberExpression()->Compile(pg, thisReg); } else if (realCallee->IsChainExpression()) { - hasThis = true; + hasThis = realCallee->AsChainExpression()->GetExpression()->IsMemberExpression(); realCallee->AsChainExpression()->Compile(pg); } else { realCallee->Compile(pg); diff --git a/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee-expected.txt b/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee-expected.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee.js b/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee.js new file mode 100644 index 0000000000..d19c4bafc0 --- /dev/null +++ b/es2panda/test/compiler/js/call-expression-with-chain-expression-as-callee.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 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 a = { + A() { + return ()=>{print(1)}; + } +}; + +(a?.A())?.(); \ No newline at end of file -- Gitee