From 9c4e086a6ea7789c8f037f67d32039d272ceee74 Mon Sep 17 00:00:00 2001 From: Botond Baranyi <botond.baranyi@ericsson.com> Date: Thu, 21 Feb 2019 13:33:03 +0100 Subject: [PATCH] Fixed has_defval and get_defval functions (bug 544632) Change-Id: I4f8360e5254bb60dc5463164af49d3f8e1b8750d Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com> --- compiler2/ttcn3/AST_ttcn3.cc | 15 ++++++++----- compiler2/ttcn3/AST_ttcn3.hh | 5 +++++ .../TTCN3_SA_ttcn3adhoc_TD.script | 21 +++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/compiler2/ttcn3/AST_ttcn3.cc b/compiler2/ttcn3/AST_ttcn3.cc index c0f57ea43..5d8a28e7c 100644 --- a/compiler2/ttcn3/AST_ttcn3.cc +++ b/compiler2/ttcn3/AST_ttcn3.cc @@ -4504,7 +4504,7 @@ namespace Ttcn { FormalPar *local_fp = fp_list->get_fp_byIndex(i); if (local_fp->has_notused_defval()) { FormalPar *base_fp = base_fpl->get_fp_byIndex(i); - if (base_fp->has_defval()) { + if (base_fp->has_defval_checked()) { local_fp->set_defval(base_fp->get_defval()); } else { local_fp->error("Not used symbol (`-') doesn't have the " @@ -8530,9 +8530,14 @@ namespace Ttcn { bool FormalPar::has_defval() const { - if (checked) return defval.ap != 0; + if (checked) return has_defval_checked(); else return defval.ti != 0; } + + bool FormalPar::has_defval_checked() const + { + return checked && defval.ap != 0; + } bool FormalPar::has_notused_defval() const { @@ -9494,7 +9499,7 @@ namespace Ttcn { const string& par_name = par->get_id().get_name(); if (par->get_asstype() != Definition::A_PAR_TIMER) par->get_Type()->set_genname(p_prefix, par_name); - if (par->has_defval()) { + if (par->has_defval_checked()) { string embedded_genname(p_prefix); embedded_genname += '_'; embedded_genname += par_name; @@ -9877,7 +9882,7 @@ namespace Ttcn { static_cast<unsigned long> (i + 1), fp->get_id().get_dispname().c_str()); if (!ti->get_Type() && !ti->get_DerivedRef() && ti->get_Template() ->get_templatetype() == Template::TEMPLATE_NOTUSED) { - if (fp->has_defval()) { + if (fp->has_defval_checked()) { ActualPar *defval = fp->get_defval(); p_aplist->add(new ActualPar(defval)); if (defval->is_erroneous()) error_flag = true; @@ -9902,7 +9907,7 @@ namespace Ttcn { // (which must exist). for (size_t i = upper_limit; i < formal_pars; i++) { FormalPar *fp = pars_v[i]; - if (fp->has_defval()) { + if (fp->has_defval_checked()) { ActualPar *defval = fp->get_defval(); p_aplist->add(new ActualPar(defval)); if (defval->is_erroneous()) error_flag = true; diff --git a/compiler2/ttcn3/AST_ttcn3.hh b/compiler2/ttcn3/AST_ttcn3.hh index 602ad6fb3..7d265fb88 100644 --- a/compiler2/ttcn3/AST_ttcn3.hh +++ b/compiler2/ttcn3/AST_ttcn3.hh @@ -1769,7 +1769,12 @@ namespace Ttcn { virtual bool is_local() const; virtual Type *get_Type(); virtual void chk(); + /** Returns true if the formal parameter has a default value (whether it's + * checked or not). Does not guarantee that usage of get_defval is safe! */ bool has_defval() const; + /** Returns true if the formal parameter is checked and has a default value. + * Guarantees that usage of get_defval is safe. */ + bool has_defval_checked() const; bool has_notused_defval() const; /** Get the default value. * \pre chk() has been called (checked==true) */ diff --git a/function_test/Semantic_Analyser/TTCN3_SA_ttcn3adhoc_TD.script b/function_test/Semantic_Analyser/TTCN3_SA_ttcn3adhoc_TD.script index 6705f9bd2..97a53cd32 100644 --- a/function_test/Semantic_Analyser/TTCN3_SA_ttcn3adhoc_TD.script +++ b/function_test/Semantic_Analyser/TTCN3_SA_ttcn3adhoc_TD.script @@ -8630,4 +8630,25 @@ template MyRecF t2 := { fnum := (-infinity..0.0) }; <END_TC> :exmp. +*-----------------------------------------------------------* +:h3.Adhoc:: Bug 544632: Using same name for type and template with default value parameter +.*-----------------------------------------------------------* +:xmp tab=0. +<TC - Bug 544632: Using same name for type and template with default value parameter> + +<COMPILE> +<VERDICT_LEAF FAIL> +<MODULE TTCN Temp Temp.ttcn> +module Temp { + +template T T(template integer p := ?) := p; + +} +<END_MODULE> +<RESULT IF_FAIL COUNT 1> +is not a reference to a type +<END_RESULT> +<END_TC> +:exmp. + :etext. -- GitLab