From 195ae24dcb23c1d432838dde3fc32d05e7059cff Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Fri, 17 Feb 2017 19:54:59 +0200 Subject: [PATCH] const method cannot write to self --- src/scripting/backend/codegen.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 1ea2565cb4..f692059979 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -6709,8 +6709,14 @@ bool FxStructMember::RequestAddress(FCompileContext &ctx, bool *writable) return false; } AddressRequested = true; - if (writable != nullptr) *writable = (AddressWritable && !ctx.CheckWritable(membervar->Flags) && - (!classx->ValueType->IsKindOf(RUNTIME_CLASS(PPointer)) || !static_cast(classx->ValueType)->IsConst)); + if (writable != nullptr) + { + *writable = (AddressWritable && !ctx.CheckWritable(membervar->Flags) && + (!classx->ValueType->IsKindOf(RUNTIME_CLASS(PPointer)) || !static_cast(classx->ValueType)->IsConst)); + // [ZZ] self in a const function is not writable. + if ((classx->ExprType == EFX_Self) && (ctx.Function && (ctx.Function->Variants[0].Flags & VARF_ReadOnly))) + *writable = false; + } return true; }