diff --git a/src/language/ast/ASTNodeAffectationExpressionBuilder.cpp b/src/language/ast/ASTNodeAffectationExpressionBuilder.cpp index 32117039587e2c53907ea030ac73a7e10e544255..cc26d368ee6cb0d6a3f105604ae6484628d69890 100644 --- a/src/language/ast/ASTNodeAffectationExpressionBuilder.cpp +++ b/src/language/ast/ASTNodeAffectationExpressionBuilder.cpp @@ -37,6 +37,12 @@ ASTNodeAffectationExpressionBuilder::ASTNodeAffectationExpressionBuilder(ASTNode ASTNode& lhs_node = *node.children[0]; ASTNode& rhs_node = *node.children[1]; + if (rhs_node.m_data_type == ASTNodeDataType::list_t) { + if ((lhs_node.m_data_type == ASTNodeDataType::vector_t) or (lhs_node.m_data_type == ASTNodeDataType::matrix_t)) { + ASTNodeNaturalConversionChecker(rhs_node, lhs_node.m_data_type); + } + } + node.m_node_processor = optional_processor_builder.value()->getNodeProcessor(lhs_node, rhs_node); } else { std::ostringstream error_message; diff --git a/tests/test_AffectationProcessor.cpp b/tests/test_AffectationProcessor.cpp index ec130a135320bf1ceba5ee1ff532b57437296d2e..b6f73afdb4ec60f6b754eea3eafcbe2bf0ce0759 100644 --- a/tests/test_AffectationProcessor.cpp +++ b/tests/test_AffectationProcessor.cpp @@ -482,6 +482,13 @@ TEST_CASE("AffectationProcessor", "[language]") CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = 3.2;", "undefined affectation type: R^2 = R"); CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = 2.3;", "undefined affectation type: R^3 = R"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^1; let y : R^1x1, y = 1; x = y;", + "undefined affectation type: R^1 = R^1x1"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^2; let y : R^2x2, y = (1,2,4,4); x = y;", + "undefined affectation type: R^2 = R^2x2"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3; let y : R^3x3, y = (1,2,3,4,5,6,7,8,9); x = y;", + "undefined affectation type: R^3 = R^3x3"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = 4;", "invalid integral value (0 is the solely valid value)"); CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = 3;", "invalid integral value (0 is the solely valid value)"); @@ -499,6 +506,65 @@ TEST_CASE("AffectationProcessor", "[language]") "undefined affectation type: R^1 = R^3"); CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = 0; let y : R^2, y = x;", "undefined affectation type: R^2 = R^3"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^1, x = (1,2);", "undefined affectation type: R^1 = list"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = (1,2,3);", + "incompatible dimensions in affectation: expecting 2, but provided 3"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = (1,2);", + "incompatible dimensions in affectation: expecting 3, but provided 2"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = (1,2,3,4);", + "incompatible dimensions in affectation: expecting 3, but provided 4"); + } + + SECTION("-> R^nxn") + { + CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = \"foobar\";", "undefined affectation type: R^2x2 = string"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = \"foobar\";", "undefined affectation type: R^3x3 = string"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = 3.2;", "undefined affectation type: R^2x2 = R"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = 2.3;", "undefined affectation type: R^3x3 = R"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1; let y : R^1, y = 1; x = y;", + "undefined affectation type: R^1x1 = R^1"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2; let y : R^2, y = (1,2); x = y;", + "undefined affectation type: R^2x2 = R^2"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3; let y : R^3, y = (1,2,3); x = y;", + "undefined affectation type: R^3x3 = R^3"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2; x = 3.2;", "undefined affectation type: R^2x2 = R"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3; x = 2.3;", "undefined affectation type: R^3x3 = R"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = 4;", "invalid integral value (0 is the solely valid value)"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = 3;", "invalid integral value (0 is the solely valid value)"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1, x = 0; let y : R^2x2, y = x;", + "undefined affectation type: R^2x2 = R^1x1"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1, x = 0; let y : R^3x3, y = x;", + "undefined affectation type: R^3x3 = R^1x1"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = 0; let y : R^1x1, y = x;", + "undefined affectation type: R^1x1 = R^2x2"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = 0; let y : R^3x3, y = x;", + "undefined affectation type: R^3x3 = R^2x2"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = 0; let y : R^1x1, y = x;", + "undefined affectation type: R^1x1 = R^3x3"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = 0; let y : R^2x2, y = x;", + "undefined affectation type: R^2x2 = R^3x3"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1, x = (1,2);", "undefined affectation type: R^1x1 = list"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = (1,2,3);", + "incompatible dimensions in affectation: expecting 4, but provided 3"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = (1,2,3,4,5);", + "incompatible dimensions in affectation: expecting 4, but provided 5"); + + CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = (1,2,3,4,5,6,7,8);", + "incompatible dimensions in affectation: expecting 9, but provided 8"); + CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = (1,2,3,4,5,6,7,8,9,10);", + "incompatible dimensions in affectation: expecting 9, but provided 10"); } } }