Skip to content
Snippets Groups Projects
Commit aed5a062 authored by Jeno Attila Balasko's avatar Jeno Attila Balasko Committed by Gerrit Code Review
Browse files

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

parents 611b4d21 7dd8e4a6
No related branches found
No related tags found
No related merge requests found
...@@ -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);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment