From 7889f26fb1e45bd6a9f9dc7cec37bd6b21e53f12 Mon Sep 17 00:00:00 2001 From: turgutbababalim Date: Sun, 6 Jul 2025 21:29:15 +0300 Subject: [PATCH] Added function type check to CheckOverride Issue: ICKB3U Description: Added a IsETSFunction in function.cpp:1930 to prevent crashes on invalid parameter pack usage Signed-off-by: turgutbababalim --- ets2panda/checker/ets/function.cpp | 2 +- ets2panda/checker/ets/helpers.cpp | 2 +- .../ast/compiler/ets/invalid_param_pack.ets | 47 +++++++++++++++++++ .../ast/parser/ets/FixedArray/StringFasta.ets | 42 ++++++++--------- ets2panda/test/ast/parser/ets/StringFasta.ets | 42 ++++++++--------- 5 files changed, 91 insertions(+), 44 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/invalid_param_pack.ets diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 40a06e17af..c595701029 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1930,7 +1930,7 @@ bool ETSChecker::CheckOverride(Signature *signature, ETSObjectType *site) auto *target = site->GetProperty(signature->Function()->Id()->Name(), flags); bool isOverridingAnySignature = false; - if (target == nullptr || target->TsType() == nullptr || !target->TsType()->IsETSFunctionType()) { + if (target == nullptr || target->TsType() == nullptr || target->TsType()->IsTypeError()) { return isOverridingAnySignature; } diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 095b9f0503..05e490c3c2 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -153,7 +153,7 @@ void ETSChecker::WrongContextErrorClassifyByType(ir::Identifier *ident) void ETSChecker::NotResolvedError(ir::Identifier *const ident, const varbinder::Variable *classVar, const ETSObjectType *classType) { - if (classVar == nullptr) { + if (classVar == nullptr || (classVar->TsType() != nullptr && classVar->TsType()->IsTypeError())) { LogUnresolvedReferenceError(ident); return; } diff --git a/ets2panda/test/ast/compiler/ets/invalid_param_pack.ets b/ets2panda/test/ast/compiler/ets/invalid_param_pack.ets new file mode 100644 index 0000000000..448d15b445 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/invalid_param_pack.ets @@ -0,0 +1,47 @@ +/* + * 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 Base { + constructor(...args) { + + } +} + +class Derived extends Base{ + constructor(){ + super(3); + } +} + +class Base2 { + my_func(...args) { + + } +} + +class Derived2 extends Base2{ + constructor(){ + my_func(3); + } +} + +/* @@? 17:17 Error SyntaxError: Rest parameter should be either array or tuple type. */ +/* @@? 17:17 Error TypeError: The type of parameter 'args' cannot be inferred */ +/* @@? 17:24 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ +/* @@? 24:3 Error TypeError: No matching call signature */ +/* @@? 29:13 Error SyntaxError: Rest parameter should be either array or tuple type. */ +/* @@? 29:13 Error TypeError: The type of parameter 'args' cannot be inferred */ +/* @@? 29:20 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ +/* @@? 36:3 Error TypeError: Unresolved reference my_func */ diff --git a/ets2panda/test/ast/parser/ets/FixedArray/StringFasta.ets b/ets2panda/test/ast/parser/ets/FixedArray/StringFasta.ets index 87b568099b..3cc0fa0bcd 100644 --- a/ets2panda/test/ast/parser/ets/FixedArray/StringFasta.ets +++ b/ets2panda/test/ast/parser/ets/FixedArray/StringFasta.ets @@ -126,25 +126,25 @@ function main(): void { /* @@? 18:46 Error TypeError: Cannot find type 'HashMap'. */ /* @@? 19:22 Error TypeError: Cannot find type 'HashMap'. */ /* @@? 19:50 Error TypeError: Cannot find type 'HashMap'. */ -/* @@? 21:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 22:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 23:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 24:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 25:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 26:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 27:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 28:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 29:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 30:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 31:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 32:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 33:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 34:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 35:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 36:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 37:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 38:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 39:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ +/* @@? 21:9 Error TypeError: Unresolved reference IUB */ +/* @@? 22:9 Error TypeError: Unresolved reference IUB */ +/* @@? 23:9 Error TypeError: Unresolved reference IUB */ +/* @@? 24:9 Error TypeError: Unresolved reference IUB */ +/* @@? 25:9 Error TypeError: Unresolved reference IUB */ +/* @@? 26:9 Error TypeError: Unresolved reference IUB */ +/* @@? 27:9 Error TypeError: Unresolved reference IUB */ +/* @@? 28:9 Error TypeError: Unresolved reference IUB */ +/* @@? 29:9 Error TypeError: Unresolved reference IUB */ +/* @@? 30:9 Error TypeError: Unresolved reference IUB */ +/* @@? 31:9 Error TypeError: Unresolved reference IUB */ +/* @@? 32:9 Error TypeError: Unresolved reference IUB */ +/* @@? 33:9 Error TypeError: Unresolved reference IUB */ +/* @@? 34:9 Error TypeError: Unresolved reference IUB */ +/* @@? 35:9 Error TypeError: Unresolved reference IUB */ +/* @@? 36:9 Error TypeError: Unresolved reference HomoSap */ +/* @@? 37:9 Error TypeError: Unresolved reference HomoSap */ +/* @@? 38:9 Error TypeError: Unresolved reference HomoSap */ +/* @@? 39:9 Error TypeError: Unresolved reference HomoSap */ /* @@@ label Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ /* @@? 47:13 Error TypeError: Static property 'last' must be accessed through it's class 'Random' */ /* @@? 47:21 Error TypeError: Static property 'last' must be accessed through it's class 'Random' */ @@ -171,8 +171,8 @@ function main(): void { /* @@? 112:32 Error TypeError: Property 'count' must be accessed through 'this' */ /* @@? 113:16 Error TypeError: Static property 'fastaRandom' must be accessed through it's class 'StringFasta' */ /* @@? 113:32 Error TypeError: Property 'count' must be accessed through 'this' */ -/* @@? 113:46 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ +/* @@? 113:46 Error TypeError: Unresolved reference IUB */ /* @@? 114:16 Error TypeError: Static property 'fastaRandom' must be accessed through it's class 'StringFasta' */ /* @@? 114:32 Error TypeError: Property 'count' must be accessed through 'this' */ -/* @@? 114:46 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ +/* @@? 114:46 Error TypeError: Unresolved reference HomoSap */ /* @@? 116:36 Error TypeError: 'expected' is a static property of 'StringFasta' */ diff --git a/ets2panda/test/ast/parser/ets/StringFasta.ets b/ets2panda/test/ast/parser/ets/StringFasta.ets index 3292dd0c41..758d82839f 100644 --- a/ets2panda/test/ast/parser/ets/StringFasta.ets +++ b/ets2panda/test/ast/parser/ets/StringFasta.ets @@ -126,25 +126,25 @@ function main(): void { /* @@? 18:46 Error TypeError: Cannot find type 'HashMap'. */ /* @@? 19:22 Error TypeError: Cannot find type 'HashMap'. */ /* @@? 19:50 Error TypeError: Cannot find type 'HashMap'. */ -/* @@? 21:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 22:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 23:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 24:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 25:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 26:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 27:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 28:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 29:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 30:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 31:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 32:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 33:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 34:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 35:9 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ -/* @@? 36:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 37:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 38:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ -/* @@? 39:9 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ +/* @@? 21:9 Error TypeError: Unresolved reference IUB */ +/* @@? 22:9 Error TypeError: Unresolved reference IUB */ +/* @@? 23:9 Error TypeError: Unresolved reference IUB */ +/* @@? 24:9 Error TypeError: Unresolved reference IUB */ +/* @@? 25:9 Error TypeError: Unresolved reference IUB */ +/* @@? 26:9 Error TypeError: Unresolved reference IUB */ +/* @@? 27:9 Error TypeError: Unresolved reference IUB */ +/* @@? 28:9 Error TypeError: Unresolved reference IUB */ +/* @@? 29:9 Error TypeError: Unresolved reference IUB */ +/* @@? 30:9 Error TypeError: Unresolved reference IUB */ +/* @@? 31:9 Error TypeError: Unresolved reference IUB */ +/* @@? 32:9 Error TypeError: Unresolved reference IUB */ +/* @@? 33:9 Error TypeError: Unresolved reference IUB */ +/* @@? 34:9 Error TypeError: Unresolved reference IUB */ +/* @@? 35:9 Error TypeError: Unresolved reference IUB */ +/* @@? 36:9 Error TypeError: Unresolved reference HomoSap */ +/* @@? 37:9 Error TypeError: Unresolved reference HomoSap */ +/* @@? 38:9 Error TypeError: Unresolved reference HomoSap */ +/* @@? 39:9 Error TypeError: Unresolved reference HomoSap */ /* @@@ label Error SyntaxError: Unexpected token. A constructor, method, accessor, or property was expected. */ /* @@? 47:13 Error TypeError: Static property 'last' must be accessed through it's class 'Random' */ /* @@? 47:21 Error TypeError: Static property 'last' must be accessed through it's class 'Random' */ @@ -171,8 +171,8 @@ function main(): void { /* @@? 112:32 Error TypeError: Property 'count' must be accessed through 'this' */ /* @@? 113:16 Error TypeError: Static property 'fastaRandom' must be accessed through it's class 'StringFasta' */ /* @@? 113:32 Error TypeError: Property 'count' must be accessed through 'this' */ -/* @@? 113:46 Error TypeError: Static property 'IUB' must be accessed through it's class 'StringFasta' */ +/* @@? 113:46 Error TypeError: Unresolved reference IUB */ /* @@? 114:16 Error TypeError: Static property 'fastaRandom' must be accessed through it's class 'StringFasta' */ /* @@? 114:32 Error TypeError: Property 'count' must be accessed through 'this' */ -/* @@? 114:46 Error TypeError: Static property 'HomoSap' must be accessed through it's class 'StringFasta' */ +/* @@? 114:46 Error TypeError: Unresolved reference HomoSap */ /* @@? 116:36 Error TypeError: 'expected' is a static property of 'StringFasta' */ -- Gitee