From 4c6d0e42094a19c146626ed6c964aaece66b240c Mon Sep 17 00:00:00 2001 From: Marisa Heit Date: Thu, 4 Aug 2022 00:01:19 -0500 Subject: [PATCH] Better error message for unknown nested types --- src/common/scripting/frontend/zcc_compile.cpp | 34 +++++++++++++++++-- src/common/scripting/frontend/zcc_compile.h | 1 + 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/common/scripting/frontend/zcc_compile.cpp b/src/common/scripting/frontend/zcc_compile.cpp index 7acb56f54ae..00cc4ace412 100644 --- a/src/common/scripting/frontend/zcc_compile.cpp +++ b/src/common/scripting/frontend/zcc_compile.cpp @@ -1994,10 +1994,36 @@ PType *ZCCCompiler::ResolveUserType(ZCC_BasicType *type, ZCC_Identifier *id, PSy } if (!nativetype) return ptype; } - Error(type, "Unable to resolve %s%s as type.", nativetype? "@" : "", FName(type->UserType->Id).GetChars()); + Error(type, "Unable to resolve %s%s as a type.", nativetype? "@" : "", UserTypeName(type).GetChars()); return TypeError; } + +//========================================================================== +// +// ZCCCompiler :: UserTypeName STATIC +// +// Returns the full name for a UserType node. +// +//========================================================================== + +FString ZCCCompiler::UserTypeName(ZCC_BasicType *type) +{ + FString out; + ZCC_Identifier *id = type->UserType; + + do + { + assert(id->NodeType == AST_Identifier); + if (out.Len() > 0) + { + out += '.'; + } + out += FName(id->Id).GetChars(); + } while ((id = static_cast(id->SiblingNext)) != type->UserType); + return out; +} + //========================================================================== // // ZCCCompiler :: ResolveArraySize @@ -2339,7 +2365,11 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool } if (type->GetRegType() == REGT_NIL && type != TypeVector2 && type != TypeVector3 && type != TypeFVector2 && type != TypeFVector3) { - Error(p, "Invalid type %s for function parameter", type->DescriptiveName()); + // If it's TypeError, then an error was already given + if (type != TypeError) + { + Error(p, "Invalid type %s for function parameter", type->DescriptiveName()); + } } else if (p->Default != nullptr) { diff --git a/src/common/scripting/frontend/zcc_compile.h b/src/common/scripting/frontend/zcc_compile.h index 1a94bd82014..b6f32018d2b 100644 --- a/src/common/scripting/frontend/zcc_compile.h +++ b/src/common/scripting/frontend/zcc_compile.h @@ -135,6 +135,7 @@ class ZCCCompiler PType *DetermineType(PType *outertype, ZCC_TreeNode *field, FName name, ZCC_Type *ztype, bool allowarraytypes, bool formember); PType *ResolveArraySize(PType *baseType, ZCC_Expression *arraysize, PContainerType *cls, bool *nosize); PType *ResolveUserType(ZCC_BasicType *type, ZCC_Identifier *id, PSymbolTable *sym, bool nativetype); + static FString UserTypeName(ZCC_BasicType *type); TArray OrderStructs(); void AddStruct(TArray &new_order, ZCC_StructWork *struct_def); ZCC_StructWork *StructTypeToWork(const PStruct *type) const;