From 0ea4e182c7eded334a17298cc9bc30fa56d7ddb0 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/scripting/types.h | 1 + src/scripting/zscript/zcc_compile.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/scripting/types.h b/src/scripting/types.h index 7d2f2341c..e2d5f5f64 100644 --- a/src/scripting/types.h +++ b/src/scripting/types.h @@ -100,6 +100,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/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 51e819910..d4370578b 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -1492,8 +1492,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; } @@ -1548,6 +1552,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; } @@ -1577,6 +1585,12 @@ bool ZCCCompiler::CompileFields(PContainerType *type, TArrayNames); Fields.Delete(0); } + + if (type != nullptr) + { + type->SizeKnown = Fields.Size() == 0; + } + return Fields.Size() == 0; }