diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 095b9f0503e36efd4eabfe0252c84ded480c63d2..94b946e953da8a9aea1592e7a9f7259dd66e30bf 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -913,11 +913,15 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T ES2PANDA_ASSERT(IsAnyError()); } - // initType should not be nullptr. If an error occurs during check, set it to GlobalTypeError(). - if (bindingVar == nullptr || initType == nullptr || initType->IsTypeError()) { + if (bindingVar == nullptr) { return annotationType != nullptr ? annotationType : GlobalTypeError(); } + // initType should not be nullptr. If an error occurs during check, set it to GlobalTypeError(). + if (initType == nullptr || initType->IsTypeError()) { + return bindingVar->SetTsType(annotationType != nullptr ? annotationType : GlobalTypeError()); + } + if (typeAnnotation == nullptr && initType->IsETSFunctionType()) { annotationType = initType->AsETSFunctionType(); bindingVar->SetTsType(annotationType); diff --git a/ets2panda/test/ast/parser/ets/segmentation_fault_test1.ets b/ets2panda/test/ast/parser/ets/segmentation_fault_test1.ets new file mode 100644 index 0000000000000000000000000000000000000000..c5e9ad05f304c09b03cb90a973e47c8b9efd1113 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/segmentation_fault_test1.ets @@ -0,0 +1,24 @@ +/* + * 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. + */ + +function A(a: string) { + let b = /* @@ label */c.a; + switch (a) { + case b: + case "aa": + } +} + +/* @@@ label Error TypeError: Unresolved reference c */ \ No newline at end of file