From 80ab04ca4cfe6cc015592ed4c8468b44df6749be Mon Sep 17 00:00:00 2001
From: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
Date: Tue, 28 Mar 2017 16:52:54 +0200
Subject: [PATCH] Anytype compatibility fix

Change-Id: Idfc25a294c05989e2da53e3e79ea9251380e2ab8
---
 compiler2/Type.cc     | 19 +++++++++++++++----
 compiler2/Type.hh     |  5 +++--
 compiler2/Type_chk.cc | 13 +++++++++++--
 compiler2/Value.cc    |  4 ++--
 4 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/compiler2/Type.cc b/compiler2/Type.cc
index 29137564f..67ebfa642 100644
--- a/compiler2/Type.cc
+++ b/compiler2/Type.cc
@@ -3110,7 +3110,8 @@ namespace Common {
 
   /** \todo review, especially the string types... */
   bool Type::is_compatible_tt_tt(typetype_t p_tt1, typetype_t p_tt2,
-                                 bool p_is_asn11, bool p_is_asn12)
+                                 bool p_is_asn11, bool p_is_asn12,
+                                 bool same_module)
   {
     if (p_tt2 == T_ERROR) return true;
     switch (p_tt1) {
@@ -3253,6 +3254,8 @@ namespace Common {
       return p_tt2==T_SET_A || p_tt2==T_SET_T;
     case T_ANY:
       return p_tt2 == T_ANY || p_tt2 == T_OSTR;
+    case T_ANYTYPE:
+      return p_tt2 == T_ANYTYPE && same_module;
       // these should never appear?
     case T_REFD:
     case T_REFDSPEC:
@@ -3265,7 +3268,7 @@ namespace Common {
     }
   }
 
-  bool Type::is_compatible_tt(typetype_t p_tt, bool p_is_asn1)
+  bool Type::is_compatible_tt(typetype_t p_tt, bool p_is_asn1, Type* p_type)
   {
     chk();
     Type *t1=get_type_refd_last();
@@ -3278,8 +3281,16 @@ namespace Common {
     case T_ADDRESS:
       FATAL_ERROR("Type::is_compatible_tt()");
       return false;
-    default:
-      return is_compatible_tt_tt(t1->typetype, p_tt, is_asn1(), p_is_asn1);
+    default: {
+      bool same_mod = false;
+      if (p_type && p_type->get_my_scope()) {
+        if (t1->get_my_scope()->get_scope_mod()->get_modid().get_name() ==
+            p_type->get_my_scope()->get_scope_mod()->get_modid().get_name()) {
+          same_mod = true;
+        }
+      }
+      return is_compatible_tt_tt(t1->typetype, p_tt, is_asn1(), p_is_asn1, same_mod);
+    }
     }
   }
 
diff --git a/compiler2/Type.hh b/compiler2/Type.hh
index dabb1b70e..877de1462 100644
--- a/compiler2/Type.hh
+++ b/compiler2/Type.hh
@@ -584,13 +584,14 @@ namespace Common {
      *  typetypes for a type (e.g. T_ENUM_A and T_ENUM_T) then all
      *  combinations of those are compatible.  */
     static bool is_compatible_tt_tt(typetype_t p_tt1, typetype_t p_tt2,
-                                    bool p_is_asn11, bool p_is_asn12);
+                                    bool p_is_asn11, bool p_is_asn12,
+                                    bool same_module);
     /** Returns whether the type is compatible with \a p_tt.  Used if the
      *  other value is unfoldable, but we can determine its expr_typetype.
      *  Note: The compatibility relation is asymmetric.  The function returns
      *  true if the set of possible values in \a p_type is a subset of
      *  possible values in \a this.  */
-    bool is_compatible_tt(typetype_t p_tt, bool p_is_asn1);
+    bool is_compatible_tt(typetype_t p_tt, bool p_is_asn1, Type* p_type = 0);
     /** Returns whether this type is compatible with \a p_type.  Note: The
      *  compatibility relation is asymmetric.  The function returns true if
      *  the set of possible values in \a p_type is a subset of possible values
diff --git a/compiler2/Type_chk.cc b/compiler2/Type_chk.cc
index 00b8a43d3..408788382 100644
--- a/compiler2/Type_chk.cc
+++ b/compiler2/Type_chk.cc
@@ -105,6 +105,10 @@ void Type::chk()
     break;
   case T_ANYTYPE:
     // TODO maybe check for address type and add it automagically, then fall through
+    if(!xerattrib) {
+      xerattrib = new XerAttributes;
+    }
+    xerattrib->untagged_ = true;
   case T_SEQ_T:
   case T_SET_T:
   case T_CHOICE_T:
@@ -833,7 +837,12 @@ Value *Type::new_value_for_dfe(Type *last, const char *dfe_str, Common::Referenc
       delete v;
       return 0;
     }
-    if (!is_compatible_tt_tt(last->typetype, v->get_expr_governor_last()->typetype, last->is_asn1(), t->is_asn1())) {
+    bool same_mod = false;
+    if (last->get_my_scope()->get_scope_mod()->get_modid().get_name() ==
+        t->get_my_scope()->get_scope_mod()->get_modid().get_name()) {
+      same_mod = true;
+    }
+    if (!is_compatible_tt_tt(last->typetype, t->typetype, last->is_asn1(), t->is_asn1(), same_mod)) {
       v->get_reference()->error("Incompatible types were given to defaultForEmpty variant: `%s' instead of `%s'.\n",
         v->get_expr_governor_last()->get_typename().c_str(), last->get_typename().c_str());
       delete v;
@@ -3225,7 +3234,7 @@ bool Type::chk_this_value(Value *value, Common::Assignment *lhs, expected_value_
   case Value::V_MACRO:
     if (value->is_unfoldable(0, expected_value)) {
       typetype_t tt = value->get_expr_returntype(expected_value);
-      if (!is_compatible_tt(tt, value->is_asn1())) {
+      if (!is_compatible_tt(tt, value->is_asn1(), value->get_expr_governor_last())) {
         value->error("Incompatible value: `%s' value was expected",
                      get_typename().c_str());
         value->set_valuetype(Value::V_ERROR);
diff --git a/compiler2/Value.cc b/compiler2/Value.cc
index 2784f2a63..f0d3715cd 100644
--- a/compiler2/Value.cc
+++ b/compiler2/Value.cc
@@ -4234,8 +4234,8 @@ namespace Common {
       }
       // Deny type compatibility if no governors found.  The typetype_t must
       // be the same.  TODO: How can this happen?
-      if (!Type::is_compatible_tt_tt(tt1, tt2, false, false)
-          && !Type::is_compatible_tt_tt(tt2, tt1, false, false)) {
+      if (!Type::is_compatible_tt_tt(tt1, tt2, false, false, false)
+          && !Type::is_compatible_tt_tt(tt2, tt1, false, false, false)) {
         error("The operands of operation `%s' should be of compatible types",
               get_opname());
         set_valuetype(V_ERROR);
-- 
GitLab