Skip to content
Snippets Groups Projects
Commit 0bbc76f5 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Continue disallowing of non natural conversions

Syntax such as
``
B*B (a,b) = (1,1);
``
is now also forbidden.

Related to issue #16
parent f0c409df
No related branches found
No related tags found
2 merge requests!37Feature/language,!27Issue/16
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <node_processor/AffectationProcessor.hpp> #include <node_processor/AffectationProcessor.hpp>
#include <ASTNodeDataTypeFlattener.hpp> #include <ASTNodeDataTypeFlattener.hpp>
#include <ASTNodeNaturalConversionChecker.hpp>
template <typename OperatorT> template <typename OperatorT>
void void
...@@ -32,7 +33,8 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( ...@@ -32,7 +33,8 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor(
break; break;
} }
default: { default: {
throw parse_error("invalid operand type for affectation", std::vector{node_sub_data_type.m_parent_node.begin()}); throw parse_error("unexpected error: invalid operand type for affectation",
std::vector{node_sub_data_type.m_parent_node.begin()});
} }
} }
}; };
...@@ -73,6 +75,8 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor( ...@@ -73,6 +75,8 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor(
auto add_affectation_processor_for_value = [&](const ASTNodeDataType& value_type, auto add_affectation_processor_for_value = [&](const ASTNodeDataType& value_type,
const ASTNodeSubDataType& node_sub_data_type) { const ASTNodeSubDataType& node_sub_data_type) {
ASTNodeNaturalConversionChecker{node_sub_data_type.m_parent_node, node_sub_data_type.m_data_type, value_type};
switch (value_type) { switch (value_type) {
case ASTNodeDataType::bool_t: { case ASTNodeDataType::bool_t: {
add_affectation_processor_for_data(bool{}, node_sub_data_type); add_affectation_processor_for_data(bool{}, node_sub_data_type);
......
...@@ -116,7 +116,7 @@ B*Z*N (b,z,m) = (false, -2, n); ...@@ -116,7 +116,7 @@ B*Z*N (b,z,m) = (false, -2, n);
SECTION("with conversion R*B*Z*N") SECTION("with conversion R*B*Z*N")
{ {
std::string_view data = R"( std::string_view data = R"(
R*B*Z*N (r,b,z,m) = (3.2, 1, 6, 2); R*B*Z*N (r,b,z,m) = (3.2, true, 6, 2);
)"; )";
std::string_view result = R"( std::string_view result = R"(
...@@ -129,7 +129,7 @@ R*B*Z*N (r,b,z,m) = (3.2, 1, 6, 2); ...@@ -129,7 +129,7 @@ R*B*Z*N (r,b,z,m) = (3.2, 1, 6, 2);
| `-(language::name:m:NameProcessor) | `-(language::name:m:NameProcessor)
`-(language::expression_list:ASTNodeExpressionListProcessor) `-(language::expression_list:ASTNodeExpressionListProcessor)
+-(language::real:3.2:ValueProcessor) +-(language::real:3.2:ValueProcessor)
+-(language::integer:1:ValueProcessor) +-(language::true_kw:ValueProcessor)
+-(language::integer:6:ValueProcessor) +-(language::integer:6:ValueProcessor)
`-(language::integer:2:ValueProcessor) `-(language::integer:2:ValueProcessor)
)"; )";
...@@ -290,7 +290,7 @@ let f: R -> R, x -> x+1; ...@@ -290,7 +290,7 @@ let f: R -> R, x -> x+1;
R*R (x,y) = (f,2); R*R (x,y) = (f,2);
)"; )";
CHECK_AST_THROWS_WITH(data, std::string{"invalid operand type for affectation"}); CHECK_AST_THROWS_WITH(data, std::string{"invalid implicit conversion: function -> R"});
} }
SECTION("invalid operand type for string affectation") SECTION("invalid operand type for string affectation")
...@@ -300,7 +300,7 @@ let f: R -> R, x -> x+1; ...@@ -300,7 +300,7 @@ let f: R -> R, x -> x+1;
string*N (s,n) = (f,2); string*N (s,n) = (f,2);
)"; )";
CHECK_AST_THROWS_WITH(data, std::string{"invalid operand type for string affectation"}); CHECK_AST_THROWS_WITH(data, std::string{"invalid implicit conversion: function -> string"});
} }
SECTION("invalid value type for affectation") SECTION("invalid value type for affectation")
...@@ -312,7 +312,7 @@ R x; ...@@ -312,7 +312,7 @@ R x;
(f,x) = (3,2); (f,x) = (3,2);
)"; )";
CHECK_AST_THROWS_WITH(data, std::string{"undefined value type for tuple affectation"}); CHECK_AST_THROWS_WITH(data, std::string{"invalid implicit conversion: Z -> function"});
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment