diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index e000739bc0271af8848248f4ebb6184a9c4d7771..7d1bdcdb6f1b5e31ba387ddd014d84f525449b02 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 0000000000000000000000000000000000000000..6308a2528182ffca7f69fce93dbb8f1a8c72e2d1 --- /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