From 037f364725ba3d4f2ba50bcbe8ed91e7e73bdb2e Mon Sep 17 00:00:00 2001
From: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
Date: Wed, 21 Jun 2017 10:14:53 +0200
Subject: [PATCH] Changed error to warning on templates with port or default
 field (Bug 518511)

Change-Id: I20d8d7c1a43cb6df81cf05d447fa516ac6dbffda
Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
---
 compiler2/Type_chk.cc                         |  4 +--
 core/Default.hh                               |  1 -
 .../Semantic_Analyser/TTCN3_SA_4_TD.script    | 27 ++++++++++++++-----
 .../Semantic_Analyser/TTCN3_SA_5_TD.script    |  4 +--
 .../Semantic_Analyser/TTCN3_SA_6_TD.script    |  4 +--
 .../TTCN3_SA_ttcn3adhoc_TD.script             |  4 +--
 .../template/TempNoDefaultOrPort_SE.ttcn      |  4 +--
 .../references/references.cfg                 |  3 +++
 .../references/references.ttcn                | 23 ++++++++++++++++
 9 files changed, 57 insertions(+), 17 deletions(-)

diff --git a/compiler2/Type_chk.cc b/compiler2/Type_chk.cc
index 10663bcd3..4a7123796 100644
--- a/compiler2/Type_chk.cc
+++ b/compiler2/Type_chk.cc
@@ -5555,10 +5555,10 @@ void Type::chk_this_template_incorrect_field() {
       }
       break;
     case T_DEFAULT:
-      t->error("A template cannot contain a field with default type at any level.");
+      t->warning("A template should not contain a field with default type at any level.");
       break;
     case T_PORT:
-      t->error("A template cannot contain a field with port type at any level.");
+      t->warning("A template should not contain a field with port type at any level.");
       break;
     default:
       break;
diff --git a/core/Default.hh b/core/Default.hh
index 86baee4d0..d73d1fcf8 100644
--- a/core/Default.hh
+++ b/core/Default.hh
@@ -114,7 +114,6 @@ inline boolean operator!=(Default_Base *default_value,
   { return !(default_value == other_value); }
 
 
-//FIXME: It is not possible to create default templates (NegSem_15_TopLevel_003)
 class DEFAULT_template : public Base_Template {
   union {
     Default_Base *single_value;
diff --git a/function_test/Semantic_Analyser/TTCN3_SA_4_TD.script b/function_test/Semantic_Analyser/TTCN3_SA_4_TD.script
index fef2d119e..2ecfc4c78 100644
--- a/function_test/Semantic_Analyser/TTCN3_SA_4_TD.script
+++ b/function_test/Semantic_Analyser/TTCN3_SA_4_TD.script
@@ -811,20 +811,23 @@ module ModuleA {
         charstring field2,
         MySet      field3,
 	address    field4,
-	MyCT       field5
+	MyCT       field5,
+  default    field6
     }
-    template MyRec MyTempE := {?,?,?,?,?}          // empty parameter list
+    template MyRec MyTempE := {?,?,?,?,?,?}          // empty parameter list
     template MyRec MyTemp (
         charstring     par_1,
 	address        par_2,
 	MyCT           par_3,
+  default        par_4,
 	MySet          par_5,
 	template float par_6 ) := {
 			            field1 := par_6,
 			            field2 := par_1,
 			            field3 := par_5,
 			            field4 := par_2,
-			            field5 := par_3
+			            field5 := par_3,
+                  field6 := par_4
     }
 }
 <END_MODULE>
@@ -1732,6 +1735,8 @@ module ModuleA {
                         MyRecord    field32,
 	                address       field41,
 	                address       field42,
+                  default       field61,
+                  default       field62,
 	                MyCT        field51,
 	                MyCT        field52,
 	                float       field71,
@@ -1759,7 +1764,11 @@ module ModuleA {
                                                       field31 := par_31,
                                                       field32 := par_32,
                                                       field41 := par_41,
-                                                      field42 := par_42,
+                                                      field42 := par_42,    
+                                                      field61 := par_71,    
+                                                      field62 := par_72,
+                                                      field51 := par_61,    
+                                                      field52 := par_62,
                                                       field71 := par_51,
                                                       field72 := par_52
                       }
@@ -1811,6 +1820,8 @@ module ModuleA {
 	address       field42,
 	MyCT        field51,
 	MyCT        field52,
+  default     field61,
+  default     field62,
 	float       field71,
 	float       field72
     }
@@ -1837,6 +1848,10 @@ module ModuleA {
             field32 := par_32,
             field41 := par_41,
             field42 := par_42,
+            field51 := par_61,    
+            field52 := par_62,    
+            field61 := par_71,    
+            field62 := par_72,
             field71 := par_51,
             field72 := par_52
         }
@@ -1918,9 +1933,9 @@ module ModuleA {
 (?im)\berror\b.+?template.+?cannot.+?have.+?inout.+?parameter
 <END_RESULT>
 <RESULT IF_PASS COUNT 1>
-(?im)\berror\b.+?template.+?cannot.+?contain.+?field.+?default
+(?im)\bwarning\b.+?template.+?should.+?not.+?contain.+?field.+?default
 <END_RESULT>
-<RESULT IF_PASS COUNT 15>
+<RESULT IF_PASS COUNT 14>
 (?is)\berror:
 <END_RESULT>
 <RESULT IF_PASS POSITIVE>
diff --git a/function_test/Semantic_Analyser/TTCN3_SA_5_TD.script b/function_test/Semantic_Analyser/TTCN3_SA_5_TD.script
index ac953a42d..793220b15 100644
--- a/function_test/Semantic_Analyser/TTCN3_SA_5_TD.script
+++ b/function_test/Semantic_Analyser/TTCN3_SA_5_TD.script
@@ -5156,9 +5156,9 @@ module ModuleA {
 (?im)\berror\b.+?Type.+?mismatch.+?default.+?expected
 <END_RESULT>
 <RESULT IF_PASS COUNT 1>
-(?im)\berror\b.+?template.+?cannot.+?contain.+?field.+?default
+(?im)\bwarning\b.+?template.+?should.+?not.+?contain.+?field.+?default
 <END_RESULT>
-<RESULT IF_PASS COUNT 4>
+<RESULT IF_PASS COUNT 3>
 (?is)\berror:
 <END_RESULT>
 <RESULT IF_PASS POSITIVE>
diff --git a/function_test/Semantic_Analyser/TTCN3_SA_6_TD.script b/function_test/Semantic_Analyser/TTCN3_SA_6_TD.script
index 2934b4c62..cc99f52aa 100644
--- a/function_test/Semantic_Analyser/TTCN3_SA_6_TD.script
+++ b/function_test/Semantic_Analyser/TTCN3_SA_6_TD.script
@@ -1701,9 +1701,9 @@ template default f:= r[0];
 (?im)\bNotify\b.+?\bcode\b.+?\bnot\b.+?\bgenerated\b
 <END_RESULT>
 <RESULT IF_PASS COUNT 2>
-(?im)\berror\b.+?template.+?cannot.+?contain.+?field.+?default
+(?im)\bwarning\b.+?template.+?should.+?not.+?contain.+?field.+?default
 <END_RESULT>
-<RESULT IF_PASS COUNT 3>
+<RESULT IF_PASS COUNT 1>
 (?is)\berror:
 <END_RESULT>
 <END_TC>
diff --git a/function_test/Semantic_Analyser/TTCN3_SA_ttcn3adhoc_TD.script b/function_test/Semantic_Analyser/TTCN3_SA_ttcn3adhoc_TD.script
index 52ea49c34..568249c7a 100644
--- a/function_test/Semantic_Analyser/TTCN3_SA_ttcn3adhoc_TD.script
+++ b/function_test/Semantic_Analyser/TTCN3_SA_ttcn3adhoc_TD.script
@@ -2030,9 +2030,9 @@ module Temp {
 (?im)template.+?cannot.+?\bbe\b.+?defined.+?\bfor\b.+?port.+?type
 <END_RESULT>
 <RESULT COUNT 1>
-(?im)\berror\b.+?template.+?cannot.+?contain.+?field.+?port
+(?im)\bwarning\b.+?template.+?should.+?not.+?contain.+?field.+?port
 <END_RESULT>
-<RESULT COUNT 2>
+<RESULT COUNT 1>
 (?is)\berror:
 <END_RESULT>
 <RESULT>
diff --git a/function_test/Semantic_Analyser/template/TempNoDefaultOrPort_SE.ttcn b/function_test/Semantic_Analyser/template/TempNoDefaultOrPort_SE.ttcn
index 808345a0e..f8e3ceb78 100644
--- a/function_test/Semantic_Analyser/template/TempNoDefaultOrPort_SE.ttcn
+++ b/function_test/Semantic_Analyser/template/TempNoDefaultOrPort_SE.ttcn
@@ -12,11 +12,11 @@
 module TempNoDefaultOrPort_SE { //^In TTCN-3 module//
 
 type record MyRecordDefault { //In type \`\@TempNoDefaultOrPort\_SE\.MyRecordDefault\'// 
-    default def //In field \`def\':// //In type \`\@TempNoDefaultOrPort_SE\.MyRecordDefault\.def\'// //A template cannot contain a field with default type at any level//
+    default def //In field \`def\':// //In type \`\@TempNoDefaultOrPort_SE\.MyRecordDefault\.def\'// //A template should not contain a field with default type at any level//
   }
 
   type record MyRecordDefault2 { //In type \`\@TempNoDefaultOrPort\_SE\.MyRecordDefault2\'// 
-    default def //In field \`def\':// //In type \`\@TempNoDefaultOrPort_SE\.MyRecordDefault2\.def\'// //A template cannot contain a field with default type at any level//
+    default def //In field \`def\':// //In type \`\@TempNoDefaultOrPort_SE\.MyRecordDefault2\.def\'// //A template should not contain a field with default type at any level//
   }
 
   type record of MyRecordDefault MyRecordOfDefault; //In type \`\@TempNoDefaultOrPort\_SE\.MyRecordOfDefault\'//
diff --git a/regression_test/cfgFile/module_parameters/references/references.cfg b/regression_test/cfgFile/module_parameters/references/references.cfg
index 4b49f0907..8e628aa24 100644
--- a/regression_test/cfgFile/module_parameters/references/references.cfg
+++ b/regression_test/cfgFile/module_parameters/references/references.cfg
@@ -136,6 +136,9 @@ mptb2 := mptuni3.bval;
 # component template
 mptcomp2 := mptcomp1;
 
+# default template
+mptdef2 := mptdef1;
+
 # verdicttype template
 mptvt1 := mptvt2;
 mptvt2 := mpvt2;
diff --git a/regression_test/cfgFile/module_parameters/references/references.ttcn b/regression_test/cfgFile/module_parameters/references/references.ttcn
index 8538b6a56..fbd1cbc3b 100644
--- a/regression_test/cfgFile/module_parameters/references/references.ttcn
+++ b/regression_test/cfgFile/module_parameters/references/references.ttcn
@@ -129,6 +129,9 @@ modulepar template boolean mptb2 := false;
 modulepar template CT mptcomp1 := (null, mtc, system);
 modulepar template CT mptcomp2;
 
+modulepar template default mptdef1 := null;
+modulepar template default mptdef2;
+
 modulepar template verdicttype mptvt1 := none;
 modulepar template verdicttype mptvt2 := (pass, fail, error);
 modulepar template verdicttype mptvt3;
@@ -323,6 +326,15 @@ testcase tc_ref_component() runs on CT
   setverdict(pass);
 }
 
+testcase tc_ref_default() runs on CT
+{
+  template default t_mpdef2 := null;
+  if (not match(mpdef2, t_mpdef2)) {
+    setverdict(fail, "Expected(mpdef2): ", t_mpdef2, ", got: ", mpdef2);
+  }
+  setverdict(pass);
+}
+
 testcase tc_ref_enumerated() runs on CT
 {
   template Size t_mpenum1 := Large;
@@ -570,6 +582,15 @@ testcase tc_ref_component_template() runs on CT
   setverdict(pass);
 }
 
+testcase tc_ref_default_template() runs on CT
+{
+  template default mptdef2_exp := null;
+  if (log2str(mptdef2) != log2str(mptdef2_exp)) {
+    setverdict(fail, "Expected(mptdef2): ", mptdef2_exp, ", got: ", mptdef2);
+  }
+  setverdict(pass);
+}
+
 testcase tc_ref_enumerated_template() runs on CT
 {
   template Size mptenum1_exp := (Small, Large);
@@ -737,6 +758,7 @@ control {
   execute(tc_ref_objid());
   execute(tc_ref_verdicttype());
   execute(tc_ref_component());
+  execute(tc_ref_default());
   execute(tc_ref_enumerated());
   execute(tc_ref_record_of());
   execute(tc_ref_record());
@@ -754,6 +776,7 @@ control {
   execute(tc_ref_objid_template());
   execute(tc_ref_verdicttype_template());
   execute(tc_ref_component_template());
+  execute(tc_ref_default_template());
   execute(tc_ref_enumerated_template());
   execute(tc_ref_record_of_template());
   execute(tc_ref_record_template());
-- 
GitLab