From ff4af34478bb38ffcff4c0d58d31d6406537aa37 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 12 Sep 2019 17:10:44 +0200 Subject: [PATCH] Userdata equality should always be valid to check, even when no explicit operator is given for it --- src/Binder/Binder.cpp | 21 +++++++++++++-------- src/UserData/UserDataScriptType.hpp | 2 +- src/UserData/UserDataValue.hpp | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Binder/Binder.cpp b/src/Binder/Binder.cpp index 59b51ab..07a018b 100644 --- a/src/Binder/Binder.cpp +++ b/src/Binder/Binder.cpp @@ -421,21 +421,26 @@ namespace Porygon::Binder { auto boundLeftType = boundLeft->GetType(); auto boundRightType = boundRight->GetType(); + auto kind = expression->GetOperatorKind(); if (boundLeftType->GetClass() == TypeClass::UserData){ auto ud = dynamic_pointer_cast(boundLeftType); - auto op = ud->GetUserData()->Get()->GetBinaryOperation(expression->GetOperatorKind(), boundRightType); + auto op = ud->GetUserData()->Get()->GetBinaryOperation(kind, boundRightType); if (op == nullptr){ - this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::NoBinaryOperationFound, - expression->GetStartPosition(), - expression->GetLength()); - return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength()); + if (kind != BinaryOperatorKind::Equality && kind != BinaryOperatorKind::Inequality){ + this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::NoBinaryOperationFound, + expression->GetStartPosition(), + expression->GetLength()); + return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength()); + } + } + else{ + return new BoundUserdataBinaryExpression(boundLeft, boundRight, op, op->GetReturnType(), + expression->GetStartPosition(), expression->GetLength()); } - return new BoundUserdataBinaryExpression(boundLeft, boundRight, op, op->GetReturnType(), - expression->GetStartPosition(), expression->GetLength()); } - switch (expression->GetOperatorKind()) { + switch (kind) { case BinaryOperatorKind::Addition: if (boundLeftType->GetClass() == TypeClass::Number && boundRightType->GetClass() == TypeClass::Number) { auto leftNumeric = std::static_pointer_cast(boundLeftType); diff --git a/src/UserData/UserDataScriptType.hpp b/src/UserData/UserDataScriptType.hpp index 4f727b1..cf64226 100644 --- a/src/UserData/UserDataScriptType.hpp +++ b/src/UserData/UserDataScriptType.hpp @@ -25,7 +25,7 @@ namespace Porygon::UserData { delete _userData; } - RetrievedUserData* GetUserData() const{ + [[nodiscard]] RetrievedUserData* GetUserData() const{ return _userData; } diff --git a/src/UserData/UserDataValue.hpp b/src/UserData/UserDataValue.hpp index 1f785cf..af2c386 100644 --- a/src/UserData/UserDataValue.hpp +++ b/src/UserData/UserDataValue.hpp @@ -22,7 +22,7 @@ namespace Porygon::UserData { _obj = obj; } - ~UserDataValue(){ + ~UserDataValue() final{ delete _userData; } @@ -74,7 +74,7 @@ namespace Porygon::UserData { delete value; } - inline void* GetObjectPointer() const{ + [[nodiscard]] inline void* GetObjectPointer() const{ return _obj; }