Skip to content

Commit

Permalink
Better error message for unknown nested types
Browse files Browse the repository at this point in the history
  • Loading branch information
rheit authored and coelckers committed Aug 4, 2022
1 parent 66460bf commit 4c6d0e4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/common/scripting/frontend/zcc_compile.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/common/scripting/frontend/zcc_compile.h
Expand Up @@ -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<ZCC_StructWork *> OrderStructs();
void AddStruct(TArray<ZCC_StructWork *> &new_order, ZCC_StructWork *struct_def);
ZCC_StructWork *StructTypeToWork(const PStruct *type) const;
Expand Down

0 comments on commit 4c6d0e4

Please sign in to comment.