diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index b10a5e7edbf30a99907595fac61122e3559db908..4a45ddbe2782b82539650d8936f8e76065f775a8 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -437,6 +437,12 @@ bool ETSChecker::ValidateSignatureRequiredParams(Signature *substitutedSig, if ((flags & TypeRelationFlag::NO_CHECK_TRAILING_LAMBDA) != 0) { commonArity = commonArity - 1; } + + // Note: When the script is abnormal, the variable is redefined. + // This causes the TsType of the variable originally used as a function parameter to be modified to null. + if (commonArity > 0 && substitutedSig->Params()[0]->TsType() == nullptr) { + return false; + } for (size_t index = 0; index < commonArity; ++index) { auto &argument = arguments[index]; diff --git a/ets2panda/test/ast/compiler/ets/repeate_var.ets b/ets2panda/test/ast/compiler/ets/repeate_var.ets new file mode 100755 index 0000000000000000000000000000000000000000..f24400cea583a97383651dac633c8783108fa00d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/repeate_var.ets @@ -0,0 +1,40 @@ +/* + * 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. + */ + +import {StdDebug} from "std/debug" + +type L = StdDebug.Logger +function run_await_chain(len: int): int { + let buffer: Array + let capacity: number = 20 + + const buf = this.buffer + const len = buf.length + let arrayObj: Record = {} + for (let i = 0; i < len; i++) { + arrayObj[String(i)] = i + } +} + +function main(): int { + if (run_await_chain(50) != 0) { + L.logError("await chain test failed"); + return 1; + } +} + +/* @@? 23:17 Error TypeError: Cannot reference 'this' in this context. */ +/* @@? 23:22 Error TypeError: Property 'buffer' does not exist on type 'Error' */ +/* @@? 24:11 Error TypeError: Variable 'len' has already been declared. */