From f1d8c9f5c9966de7e7b96fe9e433359565510fbd Mon Sep 17 00:00:00 2001 From: abdulsamethaymana Date: Fri, 20 Jun 2025 14:33:56 +0300 Subject: [PATCH] Fix: #26820 Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICGR0I?from=project-issue Signed-off-by: abdulsamethaymana --- ets2panda/parser/ETSparserTypes.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ets2panda/parser/ETSparserTypes.cpp b/ets2panda/parser/ETSparserTypes.cpp index 946e7611ed..70533af98d 100644 --- a/ets2panda/parser/ETSparserTypes.cpp +++ b/ets2panda/parser/ETSparserTypes.cpp @@ -556,15 +556,31 @@ ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *optio LogError(diagnostic::INVALID_TYPE); return AllocBrokenType(beforeTypeAnnotation); } - if (!typeAnnotation->IsTSArrayType() && !typeAnnotation->IsETSTuple() && - !(typeAnnotation->IsETSTypeReference() && - typeAnnotation->AsETSTypeReference()->BaseName()->Name() == compiler::Signatures::ARRAY)) { + if (typeAnnotation->IsETSUnionType()) { + auto *unionType = typeAnnotation->AsETSUnionType(); + bool hasApplicableType = false; + for (auto *subType : unionType->Types()) { + if (subType->IsTSArrayType() || subType->IsETSTuple() || + (subType->IsETSTypeReference() && + subType->AsETSTypeReference()->BaseName()->Name() == compiler::Signatures::ARRAY)) { + hasApplicableType = true; + break; + } + } + + if (!hasApplicableType) { + LogError(diagnostic::READONLY_ONLY_ON_ARRAY_OR_TUPLE); + } + } else if (!typeAnnotation->IsTSArrayType() && !typeAnnotation->IsETSTuple() && + !(typeAnnotation->IsETSTypeReference() && + typeAnnotation->AsETSTypeReference()->BaseName()->Name() == compiler::Signatures::ARRAY)) { if (!ParseReadonlyInTypeAnnotation()) { LogError(diagnostic::READONLY_ONLY_ON_ARRAY_OR_TUPLE); } else { LogError(diagnostic::READONLY_TYPE_EXPECTED); } } + typeAnnotation->SetStart(startPos); typeAnnotation->AddModifier(ir::ModifierFlags::READONLY_PARAMETER); return typeAnnotation; -- Gitee