1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Fixed early-exit cases in ctor

This commit is contained in:
Brian Fiete 2020-12-04 06:29:25 -08:00
parent 687dde063f
commit 195a699af4
3 changed files with 33 additions and 3 deletions

View file

@ -15635,6 +15635,7 @@ void BfModule::EmitCtorBody(bool& skipBody)
bool hadInlineInitBlock = false;
BfScopeData scopeData;
scopeData.mInInitBlock = true;
auto _CheckInitBlock = [&](BfAstNode* node)
{
@ -15686,6 +15687,13 @@ void BfModule::EmitCtorBody(bool& skipBody)
hadInlineInitBlock = true;
}
else
{
// Just do a simple one
mCurMethodState->AddScope(&scopeData);
NewScopeState();
hadInlineInitBlock = true;
}
}
UpdateSrcPos(node);
@ -15769,7 +15777,7 @@ void BfModule::EmitCtorBody(bool& skipBody)
for (auto body : initBodies)
{
_CheckInitBlock(body);
VisitEmbeddedStatement(body);
VisitEmbeddedStatement(body);
}
if (hadInlineInitBlock)
@ -15777,10 +15785,19 @@ void BfModule::EmitCtorBody(bool& skipBody)
RestoreScopeState();
// This gets set to false because of AddScope but we actually are still in the head block
mCurMethodState->mInHeadScope = true;
// Make sure we emit a return even if we had a NoReturn call or return inside ourselves
mCurMethodState->mHadReturn = false;
mCurMethodState->mLeftBlockUncond = false;
}
}
else // Autocomplete case
{
BfScopeData scopeData;
scopeData.mInInitBlock = true;
mCurMethodState->AddScope(&scopeData);
NewScopeState();
// The reason we can't just do the 'normal' path for this is that the BfTypeInstance here is NOT the
// autocomplete type instance, so FieldInstance initializer values contain expressions from the full
// resolve pass, NOT the autocomplete expression
@ -15831,6 +15848,8 @@ void BfModule::EmitCtorBody(bool& skipBody)
MarkFieldInitialized(fieldInst);
}
}
RestoreScopeState();
}
}
@ -16009,7 +16028,7 @@ void BfModule::EmitCtorBody(bool& skipBody)
else
autoComplete->mIsCapturingMethodMatchInfo = false;
}
}
}
}
void BfModule::EmitEnumToStringBody()
@ -18463,6 +18482,11 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
if ((methodDef != NULL) && (propertyDeclaration != NULL) && (propertyDeclaration->mExternSpecifier != NULL))
hasExternSpecifier = true;
if ((methodDef->mMethodType == BfMethodType_CtorNoBody) && (mModuleName == "Atma_Framework_Window"))
{
NOP;
}
// Allocate, clear, set classVData
if ((methodDef->mMethodType == BfMethodType_Ctor) && (methodDef->mIsStatic))

View file

@ -403,6 +403,7 @@ public:
bool mHadScopeValueRetain;
bool mIsDeferredBlock;
bool mAllowVariableDeclarations;
bool mInInitBlock;
BfBlock* mAstBlock;
BfAstNode* mCloseNode;
BfExprEvaluator* mExprEvaluator;
@ -438,6 +439,7 @@ public:
mIsDeferredBlock = false;
mAllowTargeting = true;
mAllowVariableDeclarations = true;
mInInitBlock = false;
mMixinDepth = 0;
mScopeDepth = 0;
mScopeLocalId = -1;

View file

@ -4891,7 +4891,11 @@ void BfModule::Visit(BfReturnStatement* returnStmt)
}
return;
}
checkScope = checkScope->mPrevScope;
if (checkScope->mInInitBlock)
{
Fail("Initialization blocks cannot contain 'return' statements", returnStmt);
}
checkScope = checkScope->mPrevScope;
}
auto checkLocalAssignData = mCurMethodState->mDeferredLocalAssignData;