From bc26c54b155d46f541561ee57eabce6d10671b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Fri, 16 Feb 2024 18:43:23 -0300 Subject: [PATCH] Fix readonly native structs --- src/common/scripting/backend/codegen.cpp | 14 +++++++++++++- wadsrc/static/zscript/doombase.zs | 8 ++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index 66f99e8b4..ac3bde1e9 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -1940,6 +1940,12 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx) { bool writable; basex->RequestAddress(ctx, &writable); + + if(!writable && !ValueType->toPointer()->IsConst && ctx.Version >= MakeVersion(4, 12)) + { + ScriptPosition.Message(MSG_ERROR, "Trying to assign readonly value to writable type."); + } + basex->ValueType = ValueType; auto x = basex; basex = nullptr; @@ -8739,6 +8745,12 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx) if (Self->ValueType->isRealPointer()) { auto pointedType = Self->ValueType->toPointer()->PointedType; + + if(pointedType && pointedType->isStruct() && Self->ValueType->toPointer()->IsConst && ctx.Version >= MakeVersion(4, 12)) + { + isreadonly = true; + } + if (pointedType && (pointedType->isDynArray() || pointedType->isMap() || pointedType->isMapIterator())) { Self = new FxOutVarDereference(Self, Self->ScriptPosition); @@ -9268,7 +9280,7 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx) return nullptr; } } - else if (Self->ValueType->isStruct()) + else if (Self->ValueType->isStruct() && !isreadonly) { bool writable; diff --git a/wadsrc/static/zscript/doombase.zs b/wadsrc/static/zscript/doombase.zs index 5a99de9e6..2f2047b8d 100644 --- a/wadsrc/static/zscript/doombase.zs +++ b/wadsrc/static/zscript/doombase.zs @@ -583,10 +583,10 @@ struct State native native readonly bool bCanRaise; native readonly bool bDehacked; - native int DistanceTo(state other); - native bool ValidateSpriteFrame(); - native TextureID, bool, Vector2 GetSpriteTexture(int rotation, int skin = 0, Vector2 scale = (0,0), int spritenum = -1, int framenum = -1); - native bool InStateSequence(State base); + native int DistanceTo(state other) const; + native bool ValidateSpriteFrame() const; + native TextureID, bool, Vector2 GetSpriteTexture(int rotation, int skin = 0, Vector2 scale = (0,0), int spritenum = -1, int framenum = -1) const; + native bool InStateSequence(State base) const; } struct TerrainDef native