diff --git a/ets2panda/parser/ETSparserTypes.cpp b/ets2panda/parser/ETSparserTypes.cpp index 946e7611eda6860a9524045f088f7a7dd09d57ef..70533af98d965f246f68781b78f64747d297bb36 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;