Skip to content

Commit 416e8cc

Browse files
committed
[memory][scs][tests] Don't allow to sc-connectors belonging to sc-elements types
1 parent 5b40513 commit 416e8cc

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

sc-memory/sc-memory/src/scs/scs_parser.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,23 +479,33 @@ void Parser::ProcessTriple(
479479

480480
if (source.IsElementType() && (connector.GetType() == ScType::ConstPermPosArc))
481481
{
482+
if (target.m_type.IsConnector())
483+
SC_THROW_EXCEPTION(
484+
utils::ExceptionParseError,
485+
"Connector with type `" << std::string(target.m_type)
486+
<< "` can't belong to sc-element denoting type of sc-elements `" << source.GetIdtf()
487+
<< "`.");
488+
482489
std::string const & sourceIdtf = source.GetIdtf();
483490
ScType const newType = target.m_type | scs::TypeResolver::GetKeynodeType(sourceIdtf);
484491

485492
if (target.IsElementType() && !newType.CanExtendTo(ScType::ConstNodeClass))
486493
SC_THROW_EXCEPTION(
487494
utils::ExceptionParseError,
488495
"Can't extend type `" << std::string(target.m_type) << "` to type `" << std::string(newType)
489-
<< "` for element `" << target.GetIdtf() << "`, because element `" << target.GetIdtf()
490-
<< "` is element denoting type of sc-elements.");
496+
<< "` for sc-element `" << target.GetIdtf() << "`, because sc-element `" << target.GetIdtf()
497+
<< "` is sc-element denoting type of sc-elements.");
491498
else if (target.m_type.CanExtendTo(newType))
492499
target.m_type = newType;
493500
else
501+
{
502+
std::cout << newType << std::endl;
494503
SC_THROW_EXCEPTION(
495504
utils::ExceptionParseError,
496505
"Can't extend type `" << std::string(target.m_type) << "` to type `" << std::string(newType)
497-
<< "` for element `" << target.GetIdtf() << "`, because `" << std::string(newType)
506+
<< "` for sc-element `" << target.GetIdtf() << "`, because `" << std::string(newType)
498507
<< "` is not subtype of `" << std::string(target.m_type) << "`.");
508+
}
499509

500510
// TODO(NikitaZotov): Unfortunately, parser collects all sc.s-elements, and only then forms sc.s-triples based on
501511
// the parsed sc.s-elements. Due to this, it is difficult to handle cases when it is necessary not to generate a

sc-memory/sc-memory/tests/sc-memory/units/scs-helper/test_scs_helper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,13 @@ TEST_F(SCsHelperTest, DISABLED_GenerateBySCs_ContourWithExplicitlySpecifiedEleme
350350
EXPECT_FALSE(helper.GenerateBySCsText(scsData));
351351
}
352352

353+
TEST_F(SCsHelperTest, GenerateBySCs_ConnectorBelongsToElementType)
354+
{
355+
SCsHelper helper(*m_ctx, std::make_shared<DummyFileInterface>());
356+
std::string const scsData = "..contour = [* sc_node_tuple -> (sc_node_class => sc_node_tuple);; *];;";
357+
EXPECT_FALSE(helper.GenerateBySCsText(scsData));
358+
}
359+
353360
TEST_F(SCsHelperTest, GenerateBySCs_NotBaseArcBetweenElementTypesWithinStructure)
354361
{
355362
SCsHelper helper(*m_ctx, std::make_shared<DummyFileInterface>());

0 commit comments

Comments
 (0)