From 86b90e337ea32b4cbf0c4ae1aa4076a90d6138f4 Mon Sep 17 00:00:00 2001 From: Botond Baranyi <botond.baranyi@ericsson.com> Date: Wed, 13 May 2020 15:08:48 +0200 Subject: [PATCH] OOP: fixed code generated for var and var template initial values in default constructors (bug 552011) Change-Id: Ie8234fbd831eaff876800be0ed111e3c1c484f13 Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com> --- compiler2/ttcn3/AST_ttcn3.cc | 19 ++++++++++++------- regression_test/oop/oop.ttcn | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/compiler2/ttcn3/AST_ttcn3.cc b/compiler2/ttcn3/AST_ttcn3.cc index 44adfcd06..2448f1ba4 100644 --- a/compiler2/ttcn3/AST_ttcn3.cc +++ b/compiler2/ttcn3/AST_ttcn3.cc @@ -5277,8 +5277,11 @@ namespace Ttcn { if (initial_value) { char*& init = in_class ? target->temp.constructor_preamble : target->functions.init_comp; - init = initial_value->generate_code_init(init, - initial_value->get_lhs_name().c_str()); + string lhs = initial_value->get_lhs_name(); + if (in_class) { + lhs = string("this->") + lhs; + } + init = initial_value->generate_code_init(init, lhs.c_str()); } else if (clean_up) { // No initial value. target->functions.init_comp = mputprintf(target->functions.init_comp, "%s.clean_up();\n", get_genname().c_str()); @@ -5496,16 +5499,18 @@ namespace Ttcn { if (initial_value) { char*& init = in_class ? target->temp.constructor_preamble : target->functions.init_comp; + string lhs = initial_value->get_lhs_name(); + if (in_class) { + lhs = string("this->") + lhs; + } if (Common::Type::T_SEQOF == initial_value->get_my_governor()->get_typetype() || Common::Type::T_ARRAY == initial_value->get_my_governor()->get_typetype()) { - init = mputprintf(init, "%s.remove_all_permutations();\n", - initial_value->get_lhs_name().c_str()); + init = mputprintf(init, "%s.remove_all_permutations();\n", lhs.c_str()); } - init = initial_value->generate_code_init(init, - initial_value->get_lhs_name().c_str()); + init = initial_value->generate_code_init(init, lhs.c_str()); if (template_restriction!=TR_NONE && gen_restriction_check) init = Template::generate_restriction_check_code(init, - initial_value->get_lhs_name().c_str(), template_restriction); + lhs.c_str(), template_restriction); } else if (clean_up) { // No initial value. // Always reset component variables/variable templates on component // reinitialization. Fix for HM79493. diff --git a/regression_test/oop/oop.ttcn b/regression_test/oop/oop.ttcn index eabee6bdb..63601f402 100644 --- a/regression_test/oop/oop.ttcn +++ b/regression_test/oop/oop.ttcn @@ -121,8 +121,8 @@ type class SubClass extends BaseClass { type class @final FinalClass extends SubClass { private const integer m_final_const := 1; private template charstring m_final_temp := ? length (1..4); - private var float m_final_var; - private var template octetstring m_final_var_temp; + private var float m_final_var := 1.0; + private var template octetstring m_final_var_temp := ''O; public function @final f(in integer x) return integer { return super.f(x) + m_final_const + 1; -- GitLab