From 8e319a766953de6958fbf5fc630809aec7540872 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Nov 2023 07:47:23 +0100 Subject: [PATCH] allow comparisons between ints and translation IDs in pre 4.12 ZScript. --- src/common/scripting/backend/codegen.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index da487fad85..4f4fe57d59 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -3826,6 +3826,16 @@ FxExpression *FxCompareRel::Resolve(FCompileContext& ctx) delete left; left = x; } + else if (left->IsNumeric() && right->ValueType == TypeTranslationID && ctx.Version < MakeVersion(4, 12)) + { + right = new FxTypeCast(right, TypeSInt32, true); + SAFE_RESOLVE(right, ctx); + } + else if (right->IsNumeric() && left->ValueType == TypeTranslationID && ctx.Version < MakeVersion(4, 12)) + { + left = new FxTypeCast(left, TypeSInt32, true); + SAFE_RESOLVE(left, ctx); + } if (left->ValueType == TypeString || right->ValueType == TypeString) { @@ -3851,7 +3861,7 @@ FxExpression *FxCompareRel::Resolve(FCompileContext& ctx) } ValueType = TypeString; } - else if (left->IsNumeric() && right->IsNumeric()) + if (left->IsNumeric() && right->IsNumeric()) { if (left->IsInteger() && right->IsInteger()) { @@ -4118,6 +4128,17 @@ FxExpression *FxCompareEq::Resolve(FCompileContext& ctx) delete left; left = x; } + else if (left->IsNumeric() && right->ValueType == TypeTranslationID && ctx.Version < MakeVersion(4, 12)) + { + right = new FxIntCast(right, true, true); + SAFE_RESOLVE(right, ctx); + } + else if (right->IsNumeric() && left->ValueType == TypeTranslationID && ctx.Version < MakeVersion(4, 12)) + { + left = new FxTypeCast(left, TypeSInt32, true); + SAFE_RESOLVE(left, ctx); + } + // Special cases: Compare strings and names with names, sounds, colors, state labels and class types. // These are all types a string can be implicitly cast into, so for convenience, so they should when doing a comparison. if ((left->ValueType == TypeString || left->ValueType == TypeName) &&