diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index ca365e2a61a38520779e0572b1f9310578e60b12..d8df2c6a49faaf613467b806f4bf233864f33ccd 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -21,6 +21,7 @@ #include "checker/types/ets/etsTupleType.h" #include "checker/types/gradualType.h" #include "evaluate/scopedDebugInfoPlugin.h" +#include "macros.h" #include "types/signature.h" #include "compiler/lowering/ets/setJumpTarget.h" #include "checker/types/ets/etsAsyncFuncReturnType.h" @@ -1910,6 +1911,11 @@ static void SetTypeforRecordProperties(const ir::ObjectExpression *expr, checker auto *const valueType = typeArguments[1]; // Record type arguments for (auto *const recordProperty : recordProperties) { + if (!recordProperty->IsProperty()) { + checker->LogError(diagnostic::WRONG_TYPE_FOR_RECORD, {ToString(recordProperty->Type())}, + recordProperty->Start()); + continue; + } auto *const recordPropertyExpr = recordProperty->AsProperty()->Value(); recordPropertyExpr->SetPreferredType(valueType); recordPropertyExpr->Check(checker); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 26ed9ad28c6c05e1dea6f3aea8ee9436bd46b806..037f315b0ba71c86707f8a51dcd5872137324f79 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -784,7 +784,10 @@ static void CheckRecordType(ir::Expression *init, checker::Type *annotationType, auto properties = objectExpr->Properties(); for (const auto &property : properties) { - ES2PANDA_ASSERT(property->IsProperty()); + if (!property->IsProperty()) { + checker->LogError(diagnostic::WRONG_TYPE_FOR_RECORD, {ToString(property->Type())}, property->Start()); + continue; + } auto p = property->AsProperty(); p->Key()->SetPreferredType(typeArguments[0]); diff --git a/ets2panda/util/diagnostic/semantic.yaml b/ets2panda/util/diagnostic/semantic.yaml index 4c4ae2e28ecd4f21ea96d41b0697c01a66857615..9c7b6cd3ba2c18ded5303380cadc082db812fde0 100644 --- a/ets2panda/util/diagnostic/semantic.yaml +++ b/ets2panda/util/diagnostic/semantic.yaml @@ -1514,3 +1514,7 @@ semantic: - name: DYMANIC_INIT_WITH_OBJEXPR id: 382 message: "Dymanic Type {} cannot be initialize with an object expression" + +- name: WRONG_TYPE_FOR_RECORD + id: 383 + message: "Record can't be initaized with {}"