Commit 7dd8e4a6 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

OOP: fixed assignment of subclass object to a superclass reference (bug 552011)



Change-Id: I99580ddd74f5952a1c61a330b1ef9a3fe9f366fd
Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 8b440dd6
...@@ -79,6 +79,19 @@ public: ...@@ -79,6 +79,19 @@ public:
} }
} }
template <typename T2>
OBJECT_REF(OBJECT_REF<T2>& p_other) {
if (p_other != NULL_VALUE) {
ptr = dynamic_cast<T*>(*p_other);
if (ptr != NULL) {
ptr->add_ref();
}
else {
TTCN_error("Invalid dynamic type of initial value.");
}
}
}
void clean_up() { void clean_up() {
if (ptr != NULL) { if (ptr != NULL) {
if (ptr->remove_ref()) { if (ptr->remove_ref()) {
...@@ -106,6 +119,21 @@ public: ...@@ -106,6 +119,21 @@ public:
return *this; return *this;
} }
template <typename T2>
OBJECT_REF& operator=(OBJECT_REF<T2>& p_other) {
clean_up();
if (p_other != NULL_VALUE) {
ptr = dynamic_cast<T*>(*p_other);
if (ptr != NULL) {
ptr->add_ref();
}
else {
TTCN_error("Invalid dynamic type of assigned value.");
}
}
return *this;
}
boolean operator==(null_type) const { // equality operator (with null reference) boolean operator==(null_type) const { // equality operator (with null reference)
return ptr == NULL; return ptr == NULL;
} }
......
...@@ -269,6 +269,15 @@ testcase tc_equality() runs on CT { ...@@ -269,6 +269,15 @@ testcase tc_equality() runs on CT {
if (v_ref2 != v_base) { if (v_ref2 != v_base) {
setverdict(fail, "Inequality of object and indirect reference to object failed"); setverdict(fail, "Inequality of object and indirect reference to object failed");
} }
var SubClass v_sub := SubClass.create(4, { 1, 2, 4 }, "a", 'FF'O, (0.0 .. 10.0));
var BaseClass v_ref3 := v_sub;
if (not v_ref3 == v_sub) {
setverdict(fail, "Equality of subclass object and superclass reference failed");
}
if (v_ref3 != v_sub) {
setverdict(fail, "Inquality of subclass object and superclass reference failed");
}
setverdict(pass); setverdict(pass);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment