From db6c90f73a45415be00217fcf928b68549f4ac03 Mon Sep 17 00:00:00 2001 From: Utku Enes GURSEL Date: Sun, 22 Jun 2025 14:55:58 +0300 Subject: [PATCH] fix checker assertion fail Issue: ICGRFK Description: Fix checker assertion fail, when the variable cannot be found setting the type as GlobalTypeError as align with the rest of the method. Signed-off-by: Utku Enes GURSEL --- ets2panda/checker/ets/helpers.cpp | 5 +- .../ast/parser/ets/invalid_type_reference.ets | 49 +++++++++++++++++++ .../astchecker/astchecker-ets-ignored.txt | 3 +- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/ast/parser/ets/invalid_type_reference.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 26ed9ad28c..e78f9e5abc 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -1773,7 +1773,10 @@ Type *ETSChecker::GetReferencedTypeBase(ir::Expression *name) ES2PANDA_ASSERT(name->IsIdentifier()); auto *const var = name->AsIdentifier()->Variable(); - ES2PANDA_ASSERT(var != nullptr); + + if (var == nullptr) { + return name->SetTsType(GlobalTypeError()); + }; if (var->TsType() != nullptr && var->TsType()->IsTypeError()) { return name->SetTsType(GlobalTypeError()); diff --git a/ets2panda/test/ast/parser/ets/invalid_type_reference.ets b/ets2panda/test/ast/parser/ets/invalid_type_reference.ets new file mode 100644 index 0000000000..188833dc7c --- /dev/null +++ b/ets2panda/test/ast/parser/ets/invalid_type_reference.ets @@ -0,0 +1,49 @@ +/* + * 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. + */ + +const o: Record number> = { + [((): number => +("foo"))()]: function (y: string): number { + return y.length; + }, + [((): number => +("bar"))()]: (y: string): number => y.length +}; + +/* @@? 17:21 Error TypeError: Wrong operand type for unary expression */ +/* @@? 17:35 Error SyntaxError: Unexpected token 'function'. */ +/* @@? 17:46 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 17:46 Error SyntaxError: Unexpected token. */ +/* @@? 17:48 Error TypeError: Type 'String' is not compatible with type 'Double' at index 1 */ +/* @@? 17:48 Error TypeError: Type name 'string' used in the wrong context */ +/* @@? 17:54 Error SyntaxError: Unexpected token, expected ':'. */ +/* @@? 17:55 Error SyntaxError: Unexpected token ':'. */ +/* @@? 17:57 Error SyntaxError: Unexpected token. */ +/* @@? 18:9 Error SyntaxError: return keyword should be used in function body. */ +/* @@? 18:16 Error TypeError: All return statements in the function should be empty or have a value. */ +/* @@? 18:16 Error TypeError: Unresolved reference y */ +/* @@? 19:5 Error SyntaxError: Unexpected token '}'. */ +/* @@? 19:6 Error SyntaxError: Unexpected token ','. */ +/* @@? 19:6 Error TypeError: Indexed access is not supported for such expression type. */ +/* @@? 20:21 Error TypeError: Wrong operand type for unary expression */ +/* @@? 20:33 Error SyntaxError: Unexpected token ':'. */ +/* @@? 20:37 Error SyntaxError: Unexpected token ':'. */ +/* @@? 20:37 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 20:37 Error SyntaxError: Unexpected token ':'. */ +/* @@? 20:39 Error SyntaxError: Unexpected token 'string'. */ +/* @@? 20:39 Error TypeError: Type name 'string' used in the wrong context */ +/* @@? 20:45 Error SyntaxError: Unexpected token ')'. */ +/* @@? 20:46 Error SyntaxError: Unexpected token ':'. */ +/* @@? 20:48 Error SyntaxError: Unexpected token 'number'. */ +/* @@? 20:48 Error TypeError: The type of parameter 'number' cannot be inferred */ +/* @@? 21:1 Error SyntaxError: Unexpected token '}'. */ diff --git a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt index c40b6e68a0..954396c0e6 100644 --- a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt +++ b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt @@ -103,7 +103,7 @@ ast/compiler/ets/lambda_infer_type/lambda_param_type_cannot_be_determined.ets # Issue: #24605 incorrect column ast/parser/ets/named_types_2.ets -# +# ast/parser/ets/partialGenericInterface.ets ast/parser/ets/partialGenericInterface_n.ets @@ -141,6 +141,7 @@ ast/compiler/ets/FixedArray/annotation_tests/annotation_src.ets ast/compiler/ets/optionalClassProperty1.ets ast/parser/ets/for_of_02.ets ast/parser/ets/for_of_loop_variable.ets +ast/parser/ets/invalid_type_reference.ets ast/compiler/ets/dynamic-field-declaration.ets ast/parser/ets/enum15.ets -- Gitee