From a74b453a18f72facfccdf726d396c674ed6fbfdb Mon Sep 17 00:00:00 2001
From: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
Date: Tue, 28 Mar 2017 17:00:17 +0200
Subject: [PATCH] Anytype compatibility fixx

Change-Id: I1c43d3bec71be95dcd99c3203b9e2db924acaf28
Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
---
 compiler2/Type.cc                                 |  6 +++---
 compiler2/Type.hh                                 |  3 ++-
 compiler2/Type_chk.cc                             |  2 +-
 compiler2/Value.cc                                |  1 +
 compiler2/ttcn3/AST_ttcn3.cc                      |  7 +++++--
 .../xer/untagged_charenc_optional_SE.ttcn         | 15 +++++++++++++++
 6 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/compiler2/Type.cc b/compiler2/Type.cc
index 67ebfa642..1885e5d2f 100644
--- a/compiler2/Type.cc
+++ b/compiler2/Type.cc
@@ -3255,7 +3255,7 @@ namespace Common {
     case T_ANY:
       return p_tt2 == T_ANY || p_tt2 == T_OSTR;
     case T_ANYTYPE:
-      return p_tt2 == T_ANYTYPE && same_module;
+      return p_tt2 == T_ANYTYPE && same_module; // Need same module
       // these should never appear?
     case T_REFD:
     case T_REFDSPEC:
@@ -3284,8 +3284,8 @@ namespace Common {
     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()) {
+        if (t1->get_my_scope()->get_scope_mod() ==
+            p_type->get_my_scope()->get_scope_mod()) {
           same_mod = true;
         }
       }
diff --git a/compiler2/Type.hh b/compiler2/Type.hh
index 877de1462..1715ce1ff 100644
--- a/compiler2/Type.hh
+++ b/compiler2/Type.hh
@@ -582,7 +582,8 @@ namespace Common {
     /** Return whether the two typetypes are compatible.  Sometimes, this is
      *  just a question of \p p_tt1 == \p p_tt2.  When there are multiple
      *  typetypes for a type (e.g. T_ENUM_A and T_ENUM_T) then all
-     *  combinations of those are compatible.  */
+     *  combinations of those are compatible. In case of anytype the
+     *  module has to be the same  */
     static bool is_compatible_tt_tt(typetype_t p_tt1, typetype_t p_tt2,
                                     bool p_is_asn11, bool p_is_asn12,
                                     bool same_module);
diff --git a/compiler2/Type_chk.cc b/compiler2/Type_chk.cc
index 408788382..e0453be49 100644
--- a/compiler2/Type_chk.cc
+++ b/compiler2/Type_chk.cc
@@ -3227,7 +3227,7 @@ bool Type::chk_this_value(Value *value, Common::Assignment *lhs, expected_value_
     return chk_this_refd_value(value, lhs, expected_value, 0, is_str_elem);
   case Value::V_INVOKE:
     chk_this_invoked_value(value, lhs, expected_value);
-    return false; // assumes no self-ref in invoke
+    return false; // assumes no self-reference in invoke
   case Value::V_EXPR:
     if (lhs) self_ref = value->chk_expr_self_ref(lhs);
     // no break
diff --git a/compiler2/Value.cc b/compiler2/Value.cc
index f0d3715cd..eec4887ff 100644
--- a/compiler2/Value.cc
+++ b/compiler2/Value.cc
@@ -4234,6 +4234,7 @@ namespace Common {
       }
       // Deny type compatibility if no governors found.  The typetype_t must
       // be the same.  TODO: How can this happen?
+      // Default false the 5th param
       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",
diff --git a/compiler2/ttcn3/AST_ttcn3.cc b/compiler2/ttcn3/AST_ttcn3.cc
index f31abf996..3d10a8b06 100644
--- a/compiler2/ttcn3/AST_ttcn3.cc
+++ b/compiler2/ttcn3/AST_ttcn3.cc
@@ -6665,8 +6665,11 @@ namespace Ttcn {
           if (Common::Type::CT_XER == encoding_type) {
             Type* last = input_type->get_type_refd_last();
             if (last->is_untagged() &&
-              last->get_typetype() == Type::T_CHOICE_A || last->get_typetype() == Type::T_CHOICE_T) {
-              // "untagged" on the (toplevel) input type will have no effect unless it is union
+               last->get_typetype() != Type::T_CHOICE_A &&
+               last->get_typetype() != Type::T_CHOICE_T &&
+               last->get_typetype() != Type::T_ANYTYPE) {
+              // "untagged" on the (toplevel) input type will have no effect,
+              // unless it is union or anytype
               warning("UNTAGGED encoding attribute is ignored on top-level type");
             }
           }
diff --git a/function_test/Semantic_Analyser/xer/untagged_charenc_optional_SE.ttcn b/function_test/Semantic_Analyser/xer/untagged_charenc_optional_SE.ttcn
index 58cf7495e..a28a1a98a 100644
--- a/function_test/Semantic_Analyser/xer/untagged_charenc_optional_SE.ttcn
+++ b/function_test/Semantic_Analyser/xer/untagged_charenc_optional_SE.ttcn
@@ -8,6 +8,7 @@
  * Contributors:
  *   Balasko, Jeno
  *   Raduly, Csaba
+ *   Szabo, Bence Janos
  *
  ******************************************************************************/
 module untagged_charenc_optional_SE {	//^In TTCN-3 module `untagged_charenc_optional_SE'://
@@ -32,7 +33,21 @@ type record parent2 {
   unt trouble optional // no message
 }
 
+type union uni {
+	integer i
+} with {
+	variant "untagged";
+}
+
+// No top level untagged warning for unions and anytype
+external function enc_uni(in uni u) return octetstring
+with { extension "prototype(convert) encode(XER:XER_EXTENDED)" }
+
+external function enc_anytype(in anytype u) return octetstring
+with { extension "prototype(convert) encode(XER:XER_EXTENDED)" }
+
 }
 with {
 encode "XML";
+extension "anytype integer";
 }
-- 
GitLab