diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 856802a97..2b4974bda 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -1583,12 +1583,19 @@ PType *ZCCCompiler::ResolveUserType(ZCC_BasicType *type, PSymbolTable *symt) PType *ZCCCompiler::ResolveArraySize(PType *baseType, ZCC_Expression *arraysize, PSymbolTable *sym) { - // The duplicate Simplify call is necessary because if the head node gets replaced there is no way to detect the end of the list otherwise. - arraysize = Simplify(arraysize, sym, true); - ZCC_Expression *val; + TArray indices; + + // Simplify is too broken to resolve this inside the ring list so unravel the list into an array before starting to simplify its components. + auto node = arraysize; do { - val = Simplify(arraysize, sym, true); + indices.Push(node); + node = static_cast(node->SiblingNext); + } while (node != arraysize); + + for (auto node : indices) + { + auto val = Simplify(node, sym, true); if (val->Operation != PEX_ConstValue || !val->Type->IsA(RUNTIME_CLASS(PInt))) { Error(arraysize, "Array index must be an integer constant"); @@ -1601,8 +1608,7 @@ PType *ZCCCompiler::ResolveArraySize(PType *baseType, ZCC_Expression *arraysize, return TypeError; } baseType = NewArray(baseType, size); - val = static_cast(val->SiblingNext); - } while (val != arraysize); + } return baseType; }