From 0bbc76f5db38c0cc15e593e2ce421bbf5dae14fa Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Tue, 14 Jan 2020 18:12:48 +0100
Subject: [PATCH] Continue disallowing of non natural conversions

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

Related to issue #16
---
 .../ASTNodeListAffectationExpressionBuilder.cpp        |  6 +++++-
 tests/test_ASTNodeListAffectationExpressionBuilder.cpp | 10 +++++-----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/language/ASTNodeListAffectationExpressionBuilder.cpp b/src/language/ASTNodeListAffectationExpressionBuilder.cpp
index 4cc62a544..b95f4777d 100644
--- a/src/language/ASTNodeListAffectationExpressionBuilder.cpp
+++ b/src/language/ASTNodeListAffectationExpressionBuilder.cpp
@@ -4,6 +4,7 @@
 #include <node_processor/AffectationProcessor.hpp>
 
 #include <ASTNodeDataTypeFlattener.hpp>
+#include <ASTNodeNaturalConversionChecker.hpp>
 
 template <typename OperatorT>
 void
@@ -32,7 +33,8 @@ ASTNodeListAffectationExpressionBuilder::_buildAffectationProcessor(
       break;
     }
     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(
 
   auto add_affectation_processor_for_value = [&](const ASTNodeDataType& value_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) {
     case ASTNodeDataType::bool_t: {
       add_affectation_processor_for_data(bool{}, node_sub_data_type);
diff --git a/tests/test_ASTNodeListAffectationExpressionBuilder.cpp b/tests/test_ASTNodeListAffectationExpressionBuilder.cpp
index 2932203ce..19f56548e 100644
--- a/tests/test_ASTNodeListAffectationExpressionBuilder.cpp
+++ b/tests/test_ASTNodeListAffectationExpressionBuilder.cpp
@@ -116,7 +116,7 @@ B*Z*N (b,z,m) = (false, -2, n);
     SECTION("with conversion R*B*Z*N")
     {
       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"(
@@ -129,7 +129,7 @@ R*B*Z*N (r,b,z,m) = (3.2, 1, 6, 2);
      |   `-(language::name:m:NameProcessor)
      `-(language::expression_list:ASTNodeExpressionListProcessor)
          +-(language::real:3.2:ValueProcessor)
-         +-(language::integer:1:ValueProcessor)
+         +-(language::true_kw:ValueProcessor)
          +-(language::integer:6:ValueProcessor)
          `-(language::integer:2:ValueProcessor)
 )";
@@ -290,7 +290,7 @@ let f: R -> R, x -> x+1;
 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")
@@ -300,7 +300,7 @@ let f: R -> R, x -> x+1;
 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")
@@ -312,7 +312,7 @@ R x;
 (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"});
     }
   }
 }
-- 
GitLab