From 53fabb8bca6a789a6ba88cfa8a70c25bee3759a5 Mon Sep 17 00:00:00 2001 From: lirismankarina Date: Tue, 7 Nov 2023 14:29:16 +0300 Subject: [PATCH] [ets2panda] Fixed Object literal instantiating with readonly field Object literal should instantiate object with readonly field if a constructor need it Issue: #I8EMKR [ets2panda] Object literal can not instantiate object with readonly field Tests: build, ets tests, added ignored tests as active for CI Signed-off-by: lirismankarina --- ets2panda/ir/expressions/objectExpression.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ets2panda/ir/expressions/objectExpression.cpp b/ets2panda/ir/expressions/objectExpression.cpp index 4722ba826a..804baa4fd1 100644 --- a/ets2panda/ir/expressions/objectExpression.cpp +++ b/ets2panda/ir/expressions/objectExpression.cpp @@ -844,7 +844,15 @@ checker::Type *ObjectExpression::Check(checker::ETSChecker *checker) checker->ThrowTypeError({"type ", obj_type->Name(), " has no property named ", pname}, prop_expr->Start()); } checker->ValidatePropertyAccess(lv, obj_type, prop_expr->Start()); - if (lv->HasFlag(varbinder::VariableFlags::READONLY)) { + bool have_constructor = false; + for (checker::Signature *sig : obj_type->ConstructSignatures()) { + if (!sig->Params().empty()) { + have_constructor = true; + checker->ValidateSignatureAccessibility(obj_type, sig, Start()); + break; + } + } + if (lv->HasFlag(binder::VariableFlags::READONLY) && !have_constructor) { checker->ThrowTypeError({"cannot assign to readonly property ", pname}, prop_expr->Start()); } -- Gitee