Better error message for unknown nested types

This commit is contained in:
Marisa Heit 2022-08-04 00:01:19 -05:00 committed by Christoph Oelckers
parent 66460bfeb8
commit 4c6d0e4209
2 changed files with 33 additions and 2 deletions

View File

@ -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<ZCC_Identifier *>(id->SiblingNext)) != type->UserType);
return out;
}
//==========================================================================
//
// ZCCCompiler :: ResolveArraySize
@ -2338,9 +2364,13 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
}
}
if (type->GetRegType() == REGT_NIL && type != TypeVector2 && type != TypeVector3 && type != TypeFVector2 && type != TypeFVector3)
{
// 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)
{
if (flags & VARF_Out)

View File

@ -135,6 +135,7 @@ protected:
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<ZCC_StructWork *> OrderStructs();
void AddStruct(TArray<ZCC_StructWork *> &new_order, ZCC_StructWork *struct_def);
ZCC_StructWork *StructTypeToWork(const PStruct *type) const;