Userdata equality should always be valid to check, even when no explicit operator is given for it

This commit is contained in:
Deukhoofd 2019-09-12 17:10:44 +02:00
parent bd343c1b7e
commit ff4af34478
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 16 additions and 11 deletions

View File

@ -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<const UserData::UserDataScriptType>(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<const NumericScriptType>(boundLeftType);

View File

@ -25,7 +25,7 @@ namespace Porygon::UserData {
delete _userData;
}
RetrievedUserData* GetUserData() const{
[[nodiscard]] RetrievedUserData* GetUserData() const{
return _userData;
}

View File

@ -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;
}