From 9541937d21bb8d1a224322b409b25044667e3042 Mon Sep 17 00:00:00 2001 From: xuxinjie4 Date: Sat, 5 Jul 2025 16:08:30 +0800 Subject: [PATCH] Fix crash when create ETSObjectType Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICK7C3?from=project-issue Signed-off-by: xuxinjie4 --- ets2panda/checker/ets/object.cpp | 5 +++- .../test/ast/compiler/ets/invalid_object.ets | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/invalid_object.ets diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 9b36448b0bc..2ecf82f403f 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -431,8 +431,11 @@ Type *ETSChecker::BuildBasicInterfaceProperties(ir::TSInterfaceDeclaration *inte interfaceType = CreateETSObjectTypeOrBuiltin(interfaceDecl, checker::ETSObjectFlags::INTERFACE); interfaceType->SetVariable(var); var->SetTsType(interfaceType); - } else { + } else if (var->TsType()->IsETSObjectType()) { interfaceType = var->TsType()->AsETSObjectType(); + } else { + ES2PANDA_ASSERT(IsAnyError()); + return GlobalTypeError(); } ConstraintCheckScope ctScope(this); diff --git a/ets2panda/test/ast/compiler/ets/invalid_object.ets b/ets2panda/test/ast/compiler/ets/invalid_object.ets new file mode 100644 index 00000000000..6d2e5fb2a11 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/invalid_object.ets @@ -0,0 +1,28 @@ +/* + * 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. + */ + +interface Obj {} +const object1: Obj = {}; + +console.log(Objˆct.keys(object1)); + +/* @@? 19:13 Error TypeError: Class name can't be the argument of function or method. */ +/* @@? 19:13 Error TypeError: Class or interface 'Obj' cannot be used as object */ +/* @@? 19:16 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 19:16 Error SyntaxError: Unexpected token 'ˆct'. */ +/* @@? 19:16 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 19:16 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 19:16 Error TypeError: Unresolved reference ˆct */ +/* @@? 19:33 Error SyntaxError: Unexpected token ')'. */ \ No newline at end of file -- Gitee