From 0f86f3a62a50752ccc14a4ec8dcdc5a155ae3aba Mon Sep 17 00:00:00 2001 From: Chronos Ouroboros Date: Sat, 15 Aug 2020 10:35:21 -0300 Subject: [PATCH] Fixed nested structs breaking the ZScript compiler under certain circumstances. --- src/common/scripting/core/types.h | 1 + src/common/scripting/frontend/zcc_compile.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/common/scripting/core/types.h b/src/common/scripting/core/types.h index 58e2138378..eae6891ee6 100644 --- a/src/common/scripting/core/types.h +++ b/src/common/scripting/core/types.h @@ -101,6 +101,7 @@ public: VersionInfo mVersion = { 0,0,0 }; uint8_t loadOp, storeOp, moveOp, RegType, RegCount; EScopeFlags ScopeFlags = (EScopeFlags)0; + bool SizeKnown = true; PType(unsigned int size = 1, unsigned int align = 1); virtual ~PType(); diff --git a/src/common/scripting/frontend/zcc_compile.cpp b/src/common/scripting/frontend/zcc_compile.cpp index 5c73fc1cc6..0bc337bde0 100644 --- a/src/common/scripting/frontend/zcc_compile.cpp +++ b/src/common/scripting/frontend/zcc_compile.cpp @@ -1476,8 +1476,12 @@ bool ZCCCompiler::CompileFields(PContainerType *type, TArrayNames; do { - if (fieldtype->Size == 0 && !(varflags & VARF_Native)) // Size not known yet. + if ((fieldtype->Size == 0 || !fieldtype->SizeKnown) && !(varflags & VARF_Native)) // Size not known yet. { + if (type != nullptr) + { + type->SizeKnown = false; + } return false; } @@ -1532,6 +1536,10 @@ bool ZCCCompiler::CompileFields(PContainerType *type, TArraySymbols.AddSymbol(f) == nullptr) { // name is already in use + if (type != nullptr) + { + type->SizeKnown = false; + } f->Destroy(); return false; } @@ -1565,6 +1573,12 @@ bool ZCCCompiler::CompileFields(PContainerType *type, TArrayNames); Fields.Delete(0); } + + if (type != nullptr) + { + type->SizeKnown = Fields.Size() == 0; + } + return Fields.Size() == 0; }