From ece14194e7f61de1e8daccd9486a3031aa7be078 Mon Sep 17 00:00:00 2001 From: gizembusraturan Date: Mon, 28 Jul 2025 10:46:59 +0300 Subject: [PATCH] Title: crash with return type Issue: ICKSER Testing: Build Signed-off-by: gizembusraturan --- ets2panda/checker/ets/object.cpp | 5 +++ ets2panda/checker/types/typeError.h | 8 ++++ .../ets/function_signature_mismatch.ets | 40 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/function_signature_mismatch.ets diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 63b773041d..7d3bba6398 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -49,6 +49,7 @@ #include "generated/signatures.h" #include "generated/diagnostic.h" #include "util/helpers.h" +#include "checker/types/typeError.h" namespace ark::es2panda::checker { @@ -2349,6 +2350,10 @@ std::vector ETSChecker::ResolveMemberReference(const ir::Member LogError(diagnostic::EXTENSION_ACCESSOR_INVALID_CALL, {}, memberExpr->Start()); return resolveRes; } + + auto expr = const_cast(memberExpr); + FORWARD_VALUE_CHECKER_AN_ERROR(this, expr, resolveRes); + resolveRes.emplace_back(ProgramAllocator()->New(globalFunctionVar, resolvedKind)); } else { ValidateResolvedProperty(&prop, target, memberExpr->Property()->AsIdentifier(), searchFlag); diff --git a/ets2panda/checker/types/typeError.h b/ets2panda/checker/types/typeError.h index df378a1fa6..7d26760711 100644 --- a/ets2panda/checker/types/typeError.h +++ b/ets2panda/checker/types/typeError.h @@ -88,6 +88,14 @@ public: /* CC-OFFNXT(G.PRE.05) error handling. */ \ return value; \ } + +#define FORWARD_VALUE_CHECKER_AN_ERROR(etsChecker, target, value) \ + ES2PANDA_ASSERT((etsChecker) != nullptr); \ + if ((etsChecker)->IsAnyError()) { \ + (target)->SetTsType((etsChecker)->GlobalTypeError()); \ + /* CC-OFFNXT(G.PRE.05) error handling. */ \ + return value; \ + } // NOLINTEND(cppcoreguidelines-macro-usage) #endif diff --git a/ets2panda/test/ast/compiler/ets/function_signature_mismatch.ets b/ets2panda/test/ast/compiler/ets/function_signature_mismatch.ets new file mode 100644 index 0000000000..4616a1bf3d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/function_signature_mismatch.ets @@ -0,0 +1,40 @@ +/* + * 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 returnThisMember(this: { member: string }) { + return this.member; +} + +interface Container { + member: string; + returnThisMember: () => string; +} + +let container: Container; +container = { + member: "sample", + returnThisMember: returnThisMember, +}; + +function main() { + container.returnThisMember(); +} + + +/* @@? 16:1 Error TypeError: Extension function can only defined for class, interface or array. */ +/* @@? 16:33 Error SyntaxError: Using object literals to declare types in place is not supported. Please declare types and interfaces explicitly! */ +/* @@? 17:12 Error TypeError: Cannot reference 'this' in this context. */ +/* @@? 17:17 Error TypeError: Property 'member' does not exist on type 'Error' */ +/* @@? 28:23 Error TypeError: Type '(=t: *ERROR_TYPE*) => void' is not compatible with type '() => String' at property 'returnThisMember' */ -- Gitee