From f16742b0cd466b31a89bfae58f266dc6282c0afa Mon Sep 17 00:00:00 2001 From: Botond Baranyi <botond.baranyi@ericsson.com> Date: Wed, 9 Sep 2020 17:24:37 +0200 Subject: [PATCH] OOP: fixed usage of 'this' as actual parameter in a function call (Bug 563718) Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com> Change-Id: Iabbfe5461545d9e02418d140b0374d927abb0e79 --- compiler2/ttcn3/AST_ttcn3.cc | 9 +++++++-- regression_test/oop/oop.ttcn | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/compiler2/ttcn3/AST_ttcn3.cc b/compiler2/ttcn3/AST_ttcn3.cc index e5d3569b2..c0022fc51 100644 --- a/compiler2/ttcn3/AST_ttcn3.cc +++ b/compiler2/ttcn3/AST_ttcn3.cc @@ -1039,6 +1039,9 @@ namespace Ttcn { if (!Ref_base::has_single_expr()) { return false; } + if (reftype == REF_THIS && id == NULL) { + return false; + } if (parlist != NULL) { Common::Assignment* ass = get_refd_assignment(); const FormalParList* fplist = (ass != NULL) ? ass->get_FormalParList() : NULL; @@ -1124,8 +1127,10 @@ namespace Ttcn { expr->expr = mputstr(expr->expr, "this->"); } else { // no 'id' means it's just a 'this' reference - expr->expr = mputprintf(expr->expr, "%s(this)", - ass->get_Type()->get_genname_value(my_scope).c_str()); + string tmp_id = my_scope->get_scope_mod_gen()->get_temporary_id(); + expr->preamble = mputprintf(expr->preamble, "%s %s(this);\n", + ass->get_Type()->get_genname_value(my_scope).c_str(), tmp_id.c_str()); + expr->expr = mputprintf(expr->expr, "%s", tmp_id.c_str()); return; } } diff --git a/regression_test/oop/oop.ttcn b/regression_test/oop/oop.ttcn index 4b3f6272d..381a005c9 100644 --- a/regression_test/oop/oop.ttcn +++ b/regression_test/oop/oop.ttcn @@ -33,6 +33,10 @@ type union Uni { charstring cs } +function f_this_as_param(object p) { + log(p); +} + type class BaseClass runs on CT mtc CT system CT { public const integer m_const := 1; private const IntList m_const2 := { 1, 2, 3 }; @@ -96,6 +100,7 @@ type class BaseClass runs on CT mtc CT system CT { if (this != v_ref2) { setverdict(fail, "inequality failed"); } + f_this_as_param(this); } } finally { -- GitLab