diff --git a/compiler2/Type.cc b/compiler2/Type.cc
index 648250cd6434cc50087508472fcf50234dffc261..e466afb327c2970f4da74345d11ca9e5bbb7ee8f 100644
--- a/compiler2/Type.cc
+++ b/compiler2/Type.cc
@@ -3271,7 +3271,7 @@ namespace Common {
     }
   }
   
-  void Type::add_coding(const string& name)
+  void Type::add_coding(const string& name, bool silent)
   {
     if (legacy_codec_handling) {
       FATAL_ERROR("Type::add_coding");
@@ -3293,7 +3293,7 @@ namespace Common {
         coding_table.add(new_coding);
         get_type_refd_last()->set_gen_coder_functions(built_in_coding);
       }
-      else if (!is_asn1()) {
+      else if (!silent) {
         // TODO: if an ASN.1 type cannot have a specific encoding,
         // it shouldn't be given that encoding in 'Type::chk_encodings'
         warning("Type `%s' cannot have %s encoding. Encode attribute ignored.",
diff --git a/compiler2/Type.hh b/compiler2/Type.hh
index 6dfcc32256abfe8fa8b34cfca6ef70924acfdd07..9b391e18c34bb3091c75e970effddceab18e10f5 100644
--- a/compiler2/Type.hh
+++ b/compiler2/Type.hh
@@ -481,9 +481,10 @@ namespace Common {
       * function to prevent infinite recursions. */
     class CodingCheckTracker {
       static map<Type*, void> types;
+      Type* key;
     public:
-      CodingCheckTracker(Type* t) { types.add(t, NULL); }
-      ~CodingCheckTracker() { types.erase(types.get_nth_key(types.size() - 1)); }
+      CodingCheckTracker(Type* t): key(t) { types.add(t, NULL); }
+      ~CodingCheckTracker() { types.erase(key); }
       static bool is_happening(Type* t) { return types.has_key(t); }
     };
 
@@ -650,7 +651,7 @@ namespace Common {
       * if the type can have that encoding.
       * @param name name of the encoding as it appears in the 'encode' attribute;
       * this may be the name of a built-in or a user-defined encoding */
-    void add_coding(const string& name);
+    void add_coding(const string& name, bool silent);
     
     /** Sets the encoder or decoder function for the user-defined encoding with
       * the specified name (when using new codec handling). */
diff --git a/compiler2/Type_chk.cc b/compiler2/Type_chk.cc
index 21ca1c8da28a5baf037ec9732552f82e7a16e1a7..1a2c80f870e2b7859c08d89ab8a7fa657506dc70 100644
--- a/compiler2/Type_chk.cc
+++ b/compiler2/Type_chk.cc
@@ -715,13 +715,13 @@ void Type::chk_encodings()
                         "refers to a type from a different type definition");
                     }
                     else {
-                      t->add_coding(swa->get_attribSpec().get_spec());
+                      t->add_coding(swa->get_attribSpec().get_spec(), false);
                     }
                   }
                 }
               }
               else {
-                add_coding(swa->get_attribSpec().get_spec());
+                add_coding(swa->get_attribSpec().get_spec(), false);
               }
             }
           }
@@ -733,7 +733,7 @@ void Type::chk_encodings()
           for (size_t i = 0; i < real.size(); ++i) {
             const SingleWithAttrib* swa = real[i];
             if (swa->get_attribKeyword() == SingleWithAttrib::AT_ENCODE) {
-              add_coding(swa->get_attribSpec().get_spec());
+              add_coding(swa->get_attribSpec().get_spec(), true);
             }
           }
         }
@@ -746,12 +746,12 @@ void Type::chk_encodings()
       case OT_COMP_FIELD:
       case OT_SELTYPE:
         // ASN.1 types automatically have BER, PER, XER and JSON encoding
-        add_coding(string("BER:2002"));
-        add_coding(string(get_encoding_name(CT_PER)));
-        add_coding(string(get_encoding_name(CT_JSON)));
+        add_coding(string("BER:2002"), true);
+        add_coding(string(get_encoding_name(CT_PER)), true);
+        add_coding(string(get_encoding_name(CT_JSON)), true);
         if (asn1_xer) {
           // XER encoding for ASN.1 types can be disabled with a command line option
-          add_coding(string(get_encoding_name(CT_XER)));
+          add_coding(string(get_encoding_name(CT_XER)), true);
         }
         break;
       default:
diff --git a/function_test/Semantic_Analyser/encode/encode_SE.ttcn b/function_test/Semantic_Analyser/encode/encode_SE.ttcn
index 9aa460c1271a4ce7945f688cfdf9cf5c8fa05f74..45ec45550f31b0dda11fe6786f1ceb76d75f8a42 100644
--- a/function_test/Semantic_Analyser/encode/encode_SE.ttcn
+++ b/function_test/Semantic_Analyser/encode/encode_SE.ttcn
@@ -137,4 +137,24 @@ function f2() runs on CT { //^In function definition//
   self.setencode(Rec4.f2, "TEXT"); //^In setencode statement// //^In the second argument// //The encoding string does not match any encodings of type//
 }
 
+type record Rec6 { //^In type definition// //Type `@encode_SE.Rec6' cannot have RAW encoding. Encode attribute ignored.// //Type `@encode_SE.Rec6' cannot have TEXT encoding. Encode attribute ignored.//
+  Int f1,
+  Rec1 f2,
+  Rec6 f3 optional,
+  SetOf2 f4,
+  record of Rec6 f5,
+  bitstring f6,
+  objid f7
+}
+with {
+  encode "XML";
+  encode "JSON";
+  encode "RAW";
+  encode "TEXT";
+  variant (f3) "JSON"."JSON: name as ff1";
+  variant (f5) "XML"."list";
+}
+
+type integer Int;
+
 }
diff --git a/function_test/Semantic_Analyser/encode/encode_grp_mod_SE.ttcn b/function_test/Semantic_Analyser/encode/encode_grp_mod_SE.ttcn
index b1c32b9d000b01abf41b025d8939af0eb8f2d931..32125720444a572d3694b368f0ec31c52b1cd889 100644
--- a/function_test/Semantic_Analyser/encode/encode_grp_mod_SE.ttcn
+++ b/function_test/Semantic_Analyser/encode/encode_grp_mod_SE.ttcn
@@ -63,6 +63,9 @@ with {
   variant "BYTEORDER(first)"; //Variant attribute is not related to TEXT encoding//
 }
 
+type component CT {}
+type port PT message { inout integer }
+
 }
 with {
   encode "JSON";