diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 95113ed59c675d244b23db736b586f42413d9e07..650a06762780cbffd1995ba8922c7f6bb0e8c64b 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -2703,6 +2703,7 @@ static checker::Type *GetTypeOfStringType(checker::Type *argType, ETSChecker *ch static checker::Type *ComputeTypeOfType(ETSChecker *checker, checker::Type *argType) { + ERROR_SANITY_CHECK(checker, argType, return argType); checker::Type *ret = nullptr; ArenaVector types(checker->ProgramAllocator()->Adapter()); ES2PANDA_ASSERT(argType != nullptr); diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 3bd487e0e0c49e4cbb19fb618c436ae6f6c307dd..a6ecd27ac6f315b2f542a6df22be97035f7108e7 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -213,15 +213,64 @@ bool ETSChecker::ProcessUntypedParameter(ir::AstNode *declNode, size_t paramInde return true; } +static bool TypeHasTypeError(checker::Type *type) +{ + if (type->IsTypeError()) { + return true; + } + + bool hasTypeErrpr = false; + + if (type->IsETSFunctionType()) { + auto funcType = type->AsETSFunctionType(); + for (auto sig : funcType->CallSignaturesOfMethodOrArrow()) { + hasTypeErrpr |= TypeHasTypeError(sig->ReturnType()); + for (auto var : sig->Params()) { + hasTypeErrpr |= TypeHasTypeError(var->TsType()); + } + + if (sig->RestVar() != nullptr) { + hasTypeErrpr |= TypeHasTypeError(sig->RestVar()->TsType()); + } + } + } + + if (type->IsETSUnionType()) { + auto unionType = type->AsETSUnionType(); + for (auto ctype : unionType->ConstituentTypes()) { + hasTypeErrpr |= TypeHasTypeError(ctype); + } + } + + if (type->IsETSArrayType()) { + auto arrayType = type->AsETSArrayType(); + hasTypeErrpr |= TypeHasTypeError(arrayType->ElementType()); + } + + if (type->IsETSResizableArrayType()) { + auto arrayType = type->AsETSResizableArrayType(); + hasTypeErrpr |= TypeHasTypeError(arrayType->ElementType()); + } + + if (type->IsETSTupleType()) { + auto tupleType = type->AsETSTupleType(); + for (auto ctype : tupleType->GetTupleTypesList()) { + hasTypeErrpr |= TypeHasTypeError(ctype); + } + } + + return hasTypeErrpr; +} + static void RemoveInvalidTypeMarkers(ir::AstNode *node) noexcept { std::function doNode = [&](ir::AstNode *nn) { if (nn->IsTyped() && !(nn->IsExpression() && nn->AsExpression()->IsTypeNode()) && - nn->AsTyped()->TsType() != nullptr && nn->AsTyped()->TsType()->IsTypeError()) { + nn->AsTyped()->TsType() != nullptr && TypeHasTypeError(nn->AsTyped()->TsType())) { nn->AsTyped()->SetTsType(nullptr); } if (nn->IsIdentifier() && nn->AsIdentifier()->TsType() != nullptr && - nn->AsIdentifier()->TsType()->IsTypeError()) { + TypeHasTypeError(nn->AsIdentifier()->TsType())) { nn->AsIdentifier()->SetVariable(nullptr); } if (!nn->IsETSTypeReference()) { diff --git a/ets2panda/compiler/lowering/ets/unboxLowering.cpp b/ets2panda/compiler/lowering/ets/unboxLowering.cpp index 2ad5b19d6968247440f6ae5859b1fe17543e5c82..86dc3e6739e5b01f1912db8fcfe456a0787fd475 100644 --- a/ets2panda/compiler/lowering/ets/unboxLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unboxLowering.cpp @@ -949,20 +949,22 @@ struct UnboxVisitor : public ir::visitor::EmptyAstVisitor { void HandleArithmeticLike(ir::BinaryExpression *bexpr) { + auto leftTp = bexpr->Left()->Check(uctx_->checker); + auto rightTp = bexpr->Right()->Check(uctx_->checker); bexpr->SetTsType(uctx_->checker->MaybeUnboxType(bexpr->TsType())); bexpr->SetOperationType(uctx_->checker->MaybeUnboxType(bexpr->OperationType())); - if (TypeIsBoxedPrimitive(bexpr->Left()->TsType())) { + if (TypeIsBoxedPrimitive(leftTp)) { bexpr->SetLeft(InsertUnboxing(uctx_, bexpr->Left())); } - if (TypeIsBoxedPrimitive(bexpr->Right()->TsType())) { + if (TypeIsBoxedPrimitive(rightTp)) { bexpr->SetRight(InsertUnboxing(uctx_, bexpr->Right())); } } void HandleEqualityOrInequality(ir::BinaryExpression *bexpr) { - auto *leftTp = bexpr->Left()->TsType(); - auto *rightTp = bexpr->Right()->TsType(); + auto leftTp = bexpr->Left()->Check(uctx_->checker); + auto rightTp = bexpr->Right()->Check(uctx_->checker); checker::Type *opType = nullptr; if ((leftTp->IsETSPrimitiveType() || TypeIsBoxedPrimitive(leftTp)) && diff --git a/ets2panda/test/ast/compiler/ets/inferTypeLambda_1.ets b/ets2panda/test/ast/compiler/ets/inferTypeLambda_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..2727c15e2e6bc0651c4ff40b6721edcc7be97d0c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/inferTypeLambda_1.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +async function foo() { } + + +foo().catch(err => { + err?.message // ok, no cte +}) \ No newline at end of file