From 186f85d8bdda7548a51dca614352275b2b1e4bde Mon Sep 17 00:00:00 2001 From: yp9522 Date: Fri, 11 Jul 2025 16:04:50 +0800 Subject: [PATCH] fix ValidateThisUsage nullptr Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICLPJZ Signed-off-by: yp9522 --- ets2panda/checker/ets/typeCheckingHelpers.cpp | 10 +++++--- ...eturnTypeAnnotation_typeParams_nullptr.ets | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100755 ets2panda/test/ast/compiler/ets/returnTypeAnnotation_typeParams_nullptr.ets diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index e000739bc0..7d1bdcdb6f 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -1076,11 +1076,13 @@ void ETSChecker::ValidateThisUsage(const ir::TypeNode *returnTypeAnnotation) } if (returnTypeAnnotation->IsETSTypeReference() && IsFixedArray(returnTypeAnnotation->AsETSTypeReference()->Part())) { - auto elementType = returnTypeAnnotation->AsETSTypeReference()->Part()->TypeParams()->Params()[0]; - if (CheckAndLogInvalidThisUsage(elementType, diagnostic::NOT_ALLOWED_THIS_IN_ARRAY_TYPE)) { - return; + if (returnTypeAnnotation->AsETSTypeReference()->Part()->TypeParams() != nullptr) { + auto elementType = returnTypeAnnotation->AsETSTypeReference()->Part()->TypeParams()->Params()[0]; + if (CheckAndLogInvalidThisUsage(elementType, diagnostic::NOT_ALLOWED_THIS_IN_ARRAY_TYPE)) { + return; + } + ValidateThisUsage(elementType); } - ValidateThisUsage(elementType); return; } } diff --git a/ets2panda/test/ast/compiler/ets/returnTypeAnnotation_typeParams_nullptr.ets b/ets2panda/test/ast/compiler/ets/returnTypeAnnotation_typeParams_nullptr.ets new file mode 100755 index 0000000000..6308a25281 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/returnTypeAnnotation_typeParams_nullptr.ets @@ -0,0 +1,25 @@ +/* + * 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: * + * 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 Arr { + public mp(a: int): FixedArray<()> +} + +/* @@? 16:11 Error TypeError: Only abstract or native methods can't have body. */ +/* @@? 16:24 Error TypeError: FixedArray must have only one type parameter. */ +/* @@? 16:37 Error SyntaxError: Unexpected token, expected '=>'. */ +/* @@? 16:37 Error SyntaxError: Unexpected token, expected '('. */ +/* @@? 16:37 Error SyntaxError: Invalid Type. */ +/* @@? 16:37 Error SyntaxError: Unexpected token, expected '>'. */ +/* @@? 16:37 Error SyntaxError: Unexpected token '>'. */ \ No newline at end of file -- Gitee