From 67fb60688b1e3bb219e7d093513da89c6b58995e Mon Sep 17 00:00:00 2001
From: Botond Baranyi <botond.baranyi@ericsson.com>
Date: Wed, 6 Jan 2021 15:51:48 +0100
Subject: [PATCH] OOP: class member/method names and formal parameter names of
 methods can no longer reuse names in the 'runs-on'/'system'/'mtc' component
 of the class (bug 568714)

Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com>
Change-Id: Ia1c77c7e27f574fa3fc8ed6e0b6e09d02bcaa7a5
---
 compiler2/ttcn3/AST_ttcn3.cc | 14 ++++++++------
 compiler2/ttcn3/Ttcnstuff.cc | 18 ++++++++++++++++--
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/compiler2/ttcn3/AST_ttcn3.cc b/compiler2/ttcn3/AST_ttcn3.cc
index d41b73d93..28eea3c92 100644
--- a/compiler2/ttcn3/AST_ttcn3.cc
+++ b/compiler2/ttcn3/AST_ttcn3.cc
@@ -10268,15 +10268,17 @@ namespace Ttcn {
         pars_m[name]->note("Previous definition of `%s' is here", dispname);
       } else {
         pars_m.add(name, par);
-        if (parent_scope && parent_scope->get_scope_class() == NULL &&
-            parent_scope->has_ass_withId(id)) {
-          par->error("Parameter name `%s' is not unique in the scope "
-            "hierarchy", dispname);
+        if (parent_scope && parent_scope->has_ass_withId(id)) {
           Reference ref(0, id.clone());
           Common::Assignment *ass = parent_scope->get_ass_bySRef(&ref);
           if (!ass) FATAL_ERROR("FormalParList::chk()");
-          ass->note("Symbol `%s' is already defined here in a higher scope "
-            "unit", dispname);
+          if (parent_scope->get_scope_class() == NULL ||
+              !ass->get_my_scope()->is_class_scope()) {
+            par->error("Parameter name `%s' is not unique in the scope "
+              "hierarchy", dispname);
+            ass->note("Symbol `%s' is already defined here in a higher scope "
+              "unit", dispname);
+          }
         }
       }
       Error_Context cntxt2(par, "In parameter `%s'", dispname);
diff --git a/compiler2/ttcn3/Ttcnstuff.cc b/compiler2/ttcn3/Ttcnstuff.cc
index d198034b9..f5bef3329 100644
--- a/compiler2/ttcn3/Ttcnstuff.cc
+++ b/compiler2/ttcn3/Ttcnstuff.cc
@@ -26,6 +26,7 @@
 #include "Statement.hh"
 #include "Templatestuff.hh"
 #include "TtcnTemplate.hh"
+#include "../CompType.hh"
 #include "../../common/path.h"
 #include "../../common/userinfo.h"
 #include "../../common/version_internal.h"
@@ -3440,11 +3441,12 @@ namespace Ttcn {
     }
 
     bool name_clash = false;
-    if (base_class != NULL) {
+    if (base_class != NULL || runs_on_type != NULL || mtc_type != NULL || system_type != NULL) {
       for (size_t i = 0; i < members->get_nof_asss(); ++i) {
         Common::Assignment* local_def = members->get_ass_byIndex(i, false);
         const Common::Identifier& local_id = local_def->get_id();
-        if (local_def->get_asstype() != Common::Assignment::A_CONSTRUCTOR &&
+        if (base_class != NULL &&
+            local_def->get_asstype() != Common::Assignment::A_CONSTRUCTOR &&
             base_class->has_local_ass_withId(local_id)) {
           Common::Assignment* base_def = base_class->get_local_ass_byId(local_id);
           switch (local_def->get_asstype()) {
@@ -3489,6 +3491,18 @@ namespace Ttcn {
             break;
           }
         }
+        if (runs_on_type != NULL && runs_on_type->get_CompBody()->has_local_ass_withId(local_id)) {
+          local_def->error("%s shadows a definition in runs-on component type `%s'",
+            local_def->get_description().c_str(), runs_on_type->get_typename().c_str());
+        }
+        if (mtc_type != NULL && mtc_type->get_CompBody()->has_local_ass_withId(local_id)) {
+          local_def->error("%s shadows a definition in mtc component type `%s'",
+            local_def->get_description().c_str(), mtc_type->get_typename().c_str());
+        }
+        if (system_type != NULL && system_type->get_CompBody()->has_local_ass_withId(local_id)) {
+          local_def->error("%s shadows a definition in system component type `%s'",
+            local_def->get_description().c_str(), system_type->get_typename().c_str());
+        }
       }
     }
     
-- 
GitLab