Skip to content

Commit

Permalink
Fixed a crash when trying to include a missing mixin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Doom2fan committed Feb 15, 2020
1 parent bd21669 commit 6486380
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/scripting/zscript/zcc_compile.cpp
Expand Up @@ -100,27 +100,23 @@ FString ZCCCompiler::StringConstFromNode(ZCC_TreeNode *node, PContainerType *cls

ZCC_MixinDef *ZCCCompiler::ResolveMixinStmt(ZCC_MixinStmt *mixinStmt, EZCCMixinType type)
{
ZCC_MixinDef *mixinDef = nullptr;

for (auto mx : Mixins)
{
if (mx->mixin->NodeName == mixinStmt->MixinName)
{
if (mx->mixin->MixinType != type)
{
Error(mixinStmt, "Mixin %s is a %s mixin cannot be used here.", FName(mixinStmt->MixinName).GetChars(), GetMixinTypeString(type));
return nullptr;
}

return mx->mixin;
}
}

if (mixinDef == nullptr)
{
Error(mixinStmt, "Mixin %s does not exist.", FName(mixinStmt->MixinName).GetChars());
}
Error(mixinStmt, "Mixin %s does not exist.", FName(mixinStmt->MixinName).GetChars());

return mixinDef;
return nullptr;
}


Expand Down Expand Up @@ -163,6 +159,7 @@ void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *treenode)
// [pbeta] Handle mixins here for the sake of simplifying things.
if (node != nullptr)
{
bool mixinError = false;
TArray<ZCC_MixinStmt *> mixinStmts;
mixinStmts.Clear();

Expand All @@ -182,6 +179,12 @@ void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *treenode)
{
ZCC_MixinDef *mixinDef = ResolveMixinStmt(mixinStmt, ZCC_Mixin_Class);

if (mixinDef == nullptr)
{
mixinError = true;
continue;
}

// Insert the mixin if there's a body. If not, just remove this node.
if (mixinDef->Body != nullptr)
{
Expand Down Expand Up @@ -230,6 +233,11 @@ void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *treenode)
}

mixinStmts.Clear();

if (mixinError)
{
return;
}
}

node = cnode->Body;
Expand Down

0 comments on commit 6486380

Please sign in to comment.