From f98a00a51de5dc3c11783f661215938aab708962 Mon Sep 17 00:00:00 2001
From: Botond Baranyi <botond.baranyi@ericsson.com>
Date: Thu, 20 Oct 2016 16:15:21 +0200
Subject: [PATCH] fixed all from in actual paramaters of function calls in
 template initializations (Bug 502442)

Change-Id: Id12b8e7d505f691ce5f10e0b4606b0e9651a91de
Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com>
---
 compiler2/ttcn3/TtcnTemplate.cc               | 11 +++++-----
 .../all_from/all_from_with_functions.ttcn     | 22 ++++++++++++++++++-
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/compiler2/ttcn3/TtcnTemplate.cc b/compiler2/ttcn3/TtcnTemplate.cc
index 2ebecec4e..4eb296f6c 100644
--- a/compiler2/ttcn3/TtcnTemplate.cc
+++ b/compiler2/ttcn3/TtcnTemplate.cc
@@ -2649,7 +2649,7 @@ end:
         u.templates = new_templates;
       }
       break; }
-
+    
     case TEMPLATE_ERROR: case TEMPLATE_NOTUSED:
     case OMIT_VALUE:     case ANY_VALUE: case ANY_OR_OMIT:
     case SPECIFIC_VALUE:
@@ -3439,7 +3439,6 @@ end:
     switch (templatetype) {
     case ALL_FROM:
     case VALUE_LIST_ALL_FROM:
-    case DECODE_MATCH:
       return false;
     case TEMPLATE_ERROR: /**< erroneous template */
     case TEMPLATE_NOTUSED: /**< not used symbol (-) */
@@ -3455,6 +3454,7 @@ end:
     case CSTR_PATTERN: /**< character string pattern */
     case USTR_PATTERN:  /**< universal charstring pattern */
     case TEMPLATE_INVOKE:
+    case DECODE_MATCH:
       // Simple templates can be computed at compile time
       return true;
 
@@ -3510,10 +3510,9 @@ end:
       const char *oftype_name_str = oftype_name.c_str();
 
       ReferenceChain refch (this, "While searching template");
-      if (!flattened || my_scope->get_statementblock_scope()) { // this "if" may be redundant if all non-var templates are flattened
-        str = mputstr(str, "// this is a var template\n");
-
-        if (compile_time()) goto compile_time;
+      
+      if (compile_time()) goto compile_time;
+      {
         // run-time, variable sized init
 
         // This is a record-of var template, like this:
diff --git a/regression_test/all_from/all_from_with_functions.ttcn b/regression_test/all_from/all_from_with_functions.ttcn
index 6fbae271f..b6d297a6e 100644
--- a/regression_test/all_from/all_from_with_functions.ttcn
+++ b/regression_test/all_from/all_from_with_functions.ttcn
@@ -104,7 +104,7 @@ testcase tc_all_from_with_functions() runs on CT_Empty {
   else { setverdict(fail) }
 }
 
-// all from with function parameters
+// all from with function (formal) parameters
 function f_all_from_params(in RoI p_in, inout RoI p_inout,
                            in template RoI pt_in, inout template RoI pt_inout)
                            runs on CT_Empty
@@ -165,11 +165,31 @@ testcase tc_all_from_with_functions2() runs on CT_Empty
   setverdict(pass);
 }
 
+// all from used in function actual parameters
+template RoI t := { 6, 8 };
+template RoI t_func_par := f_dummy( { 1, 2, all from t });
+template RoI t_func_par_exp := { 1, 2, 6, 8 };
+
+testcase tc_all_from_func_params2() runs on CT_Empty
+{
+  if (log2str(t_func_par) != log2str(t_func_par_exp)) {
+    setverdict(fail, "Template test failed. Expected: ", t_func_par_exp, ", got: ", t_func_par);
+  }
+  
+  var template RoI vt_func_par := f_dummy( { 1, 2, all from t });
+  if (log2str(vt_func_par) != log2str(t_func_par_exp)) {
+    setverdict(fail, "Var template test failed. Expected: ", t_func_par_exp, ", got: ", vt_func_par);
+  }
+  
+  setverdict(pass);
+}
+
 
 control {
   execute(tc_all_from_with_functions());
   execute(tc_all_from_func_params());
   execute(tc_all_from_with_functions2());
+  execute(tc_all_from_func_params2());
 }
 
 }
-- 
GitLab