diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 982937ee..8b917596 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -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)) diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index 85b84005..903ee543 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/IDEHelper/Compiler/BfModule.h @@ -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; diff --git a/IDEHelper/Compiler/BfStmtEvaluator.cpp b/IDEHelper/Compiler/BfStmtEvaluator.cpp index f41aa296..547f97b6 100644 --- a/IDEHelper/Compiler/BfStmtEvaluator.cpp +++ b/IDEHelper/Compiler/BfStmtEvaluator.cpp @@ -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;