- fixed: Tacking on a return statement should only be done if the function has branches that actually reach the end. Otherwise it may interfere with return type deduction.

- used the return check to optimize out unneeded jumps at the end of an if statement's first block.
This commit is contained in:
Christoph Oelckers 2016-11-05 18:05:57 +01:00
parent 98fa3d2d93
commit 1b77a8f491
4 changed files with 65 additions and 5 deletions

View file

@ -715,6 +715,13 @@ void FFunctionBuildList::Build()
FScriptPosition::StrictErrors = !item.FromDecorate;
item.Code = item.Code->Resolve(ctx);
if (!item.Code->CheckReturn())
{
auto newcmpd = new FxCompoundStatement(item.Code->ScriptPosition);
newcmpd->Add(item.Code);
newcmpd->Add(new FxReturnStatement(nullptr, item.Code->ScriptPosition));
item.Code = newcmpd->Resolve(ctx);
}
item.Proto = ctx.ReturnProto;
// Make sure resolving it didn't obliterate it.