From eec08f0e24dc7d8b280e6b82c3aa5baf10902c44 Mon Sep 17 00:00:00 2001 From: Player701 <{ID}+{username}@users.noreply.github.com> Date: Fri, 3 Jun 2022 17:02:04 +0300 Subject: [PATCH] - hopefully fixed the "is" operator to work with readonly pointers. --- src/common/scripting/backend/codegen.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index 2fcbef477d..8acbe668ea 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -277,7 +277,8 @@ bool AreCompatiblePointerTypes(PType *dest, PType *source, bool forcompare) // null pointers can be assigned to everything, everything can be assigned to void pointers. if (fromtype == nullptr || totype == TypeVoidPtr) return true; // when comparing const-ness does not matter. - if (!forcompare && totype->IsConst != fromtype->IsConst) return false; + // If not comparing, then we should not allow const to be cast away. + if (!forcompare && fromtype->IsConst && !totype->IsConst) return false; // A type is always compatible to itself. if (fromtype == totype) return true; // Pointers to different types are only compatible if both point to an object and the source type is a child of the destination type. @@ -4793,7 +4794,7 @@ FxExpression *FxTypeCheck::Resolve(FCompileContext& ctx) } else { - left = new FxTypeCast(left, NewPointer(RUNTIME_CLASS(DObject)), false); + left = new FxTypeCast(left, NewPointer(RUNTIME_CLASS(DObject), true), false); ClassCheck = false; } right = new FxClassTypeCast(NewClassPointer(RUNTIME_CLASS(DObject)), right, false);