From 917e9f6a00842d76154453581c4d2589050e3726 Mon Sep 17 00:00:00 2001 From: oh-rgx Date: Mon, 14 Jul 2025 19:56:52 +0800 Subject: [PATCH] Fix several crash Issue: #ICM8QW Signed-off-by: oh-rgx --- ets2panda/parser/ETSparserAnnotations.cpp | 3 +++ .../ast/compiler/ets/function_namespace.ets | 24 ++++++++++++++++++ .../ast/compiler/ets/function_signature.ets | 25 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/function_namespace.ets create mode 100644 ets2panda/test/ast/compiler/ets/function_signature.ets diff --git a/ets2panda/parser/ETSparserAnnotations.cpp b/ets2panda/parser/ETSparserAnnotations.cpp index cdf4dfb5d0..452d35330e 100644 --- a/ets2panda/parser/ETSparserAnnotations.cpp +++ b/ets2panda/parser/ETSparserAnnotations.cpp @@ -373,6 +373,9 @@ static lexer::SourcePosition GetExpressionEndLoc(ir::Expression *expr) return expr->AsIdentifier()->End(); } auto *part = expr->AsETSTypeReference()->Part(); + if (part->Name()->IsBrokenExpression()) { + return part->Name()->End(); + } return part->Name()->AsTSQualifiedName()->Right()->End(); } diff --git a/ets2panda/test/ast/compiler/ets/function_namespace.ets b/ets2panda/test/ast/compiler/ets/function_namespace.ets new file mode 100644 index 0000000000..218177cc05 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/function_namespace.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 main () { +export namespace taskpool { + function taskfinished(task:Task) : boolean {} + +/* @@? 17:1 Error SyntaxError: Unexpected token 'export'. */ +/* @@? 17:8 Error SyntaxError: Namespace is allowed only at the top level or inside a namespace. */ +/* @@? 18:32 Error TypeError: Cannot find type 'Task'. */ +/* @@? 25:1 Error SyntaxError: Unexpected token. */ +/* @@? 25:1 Error SyntaxError: Expected '}', got 'end of stream'. */ diff --git a/ets2panda/test/ast/compiler/ets/function_signature.ets b/ets2panda/test/ast/compiler/ets/function_signature.ets new file mode 100644 index 0000000000..1a51660182 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/function_signature.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://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. + */ + +final class TypeCreateCtx { + internal static native getObjectArrayForCCtor(ctxPtr: long): FixedArray must have only one type parameter. */ +/* @@? 17:88 Error SyntaxError: Unexpected token, expected '>'. */ +/* @@? 17:88 Error SyntaxError: Unexpected token '>'. */ +/* @@? 17:97 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:120 Error TypeError: Only abstract or native methods can't have body. */ +/* @@? 17:138 Error TypeError: Cannot find type 'RuntimeTypeDescriptor'. */ -- Gitee