diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 67c8368f..d8829d60 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -12069,6 +12069,9 @@ void BfExprEvaluator::VisitLambdaBodies(BfAstNode* body, BfFieldDtorDeclaration* BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lambdaBindExpr, BfAllocTarget& allocTarget) { + if (mModule->mCurMethodState == NULL) + return NULL; + auto rootMethodState = mModule->mCurMethodState->GetRootMethodState(); BfAstNodeList cacheNodeList; cacheNodeList.mList.Add(lambdaBindExpr); @@ -12301,6 +12304,8 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam Val128 val128(delegateTypeInstance->mTypeId); + bool isConstEval = ((mBfEvalExprFlags & BfEvalExprFlags_Comptime) != 0); + BfMethodState methodState; methodState.mPrevMethodState = mModule->mCurMethodState; BfIRFunctionType funcType; @@ -12309,7 +12314,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam funcType = mModule->mBfIRBuilder->CreateFunctionType(mModule->mBfIRBuilder->MapType(voidType), paramTypes, false); auto prevInsertBlock = mModule->mBfIRBuilder->GetInsertBlock(); - BF_ASSERT(prevInsertBlock); + BF_ASSERT(prevInsertBlock || isConstEval); auto prevActiveFunction = mModule->mBfIRBuilder->GetActiveFunction(); mModule->mBfIRBuilder->SaveDebugLocation(); @@ -12887,7 +12892,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam prevMethodState.Restore(); mModule->mBfIRBuilder->SetActiveFunction(prevActiveFunction); - if (!prevInsertBlock.IsFake()) + if ((prevInsertBlock) && (!prevInsertBlock.IsFake())) mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock); // Just a check @@ -13069,7 +13074,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam } prevClosureState.Restore(); - if (!prevInsertBlock.IsFake()) + if ((prevInsertBlock) && (!prevInsertBlock.IsFake())) mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock); for (auto& capturedEntry : capturedEntries) diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 190f3ff9..bc26bd0e 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -13648,8 +13648,11 @@ void BfModule::SetupMethodIdHash(BfMethodInstance* methodInstance) if (methodInstance->mMethodDef->mIsLocalMethod) { auto outmostMethodInstance = mCurMethodState->GetRootMethodState()->mMethodInstance; - BF_ASSERT((outmostMethodInstance->mIdHash != 0) || (outmostMethodInstance->mIsAutocompleteMethod)); - hashCtx.Mixin(outmostMethodInstance->mIdHash); + if (outmostMethodInstance != NULL) + { + BF_ASSERT((outmostMethodInstance->mIdHash != 0) || (outmostMethodInstance->mIsAutocompleteMethod)); + hashCtx.Mixin(outmostMethodInstance->mIdHash); + } } methodInstance->mIdHash = (int64)hashCtx.Finish64(); @@ -20396,7 +20399,7 @@ String BfModule::GetLocalMethodName(const StringImpl& baseName, BfAstNode* ancho } auto rootMethodState = mCurMethodState->GetRootMethodState(); - if (rootMethodState->mMethodInstance->mMethodInfoEx != NULL) + if ((rootMethodState != NULL) && (rootMethodState->mMethodInstance != NULL) && (rootMethodState->mMethodInstance->mMethodInfoEx != NULL)) { for (auto methodGenericArg : rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments) { @@ -20454,7 +20457,7 @@ BfMethodDef* BfModule::GetLocalMethodDef(BfLocalMethod* localMethod) BfMethodDef* outerMethodDef = NULL; if (localMethod->mOuterLocalMethod != NULL) outerMethodDef = localMethod->mOuterLocalMethod->mMethodDef; - else + else if (rootMethodState->mMethodInstance != NULL) outerMethodDef = rootMethodState->mMethodInstance->mMethodDef; if (methodDeclaration != NULL) @@ -20585,14 +20588,14 @@ BfModuleMethodInstance BfModule::GetLocalMethodInstance(BfLocalMethod* localMeth // Ignore the outermost method's generic method arguments for the purpose of determining if we are the 'default' (ie: unspecialized) // version of this method for this pass through the outermost method int dependentGenericStartIdx = 0; - if (rootMethodState->mMethodInstance->mMethodInfoEx != NULL) + if ((rootMethodState->mMethodInstance != NULL) && (rootMethodState->mMethodInstance->mMethodInfoEx != NULL)) dependentGenericStartIdx = (int)rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments.size(); BfMethodInstance* outerMethodInstance = mCurMethodInstance; if (methodGenericArguments.size() == 0) { - if (rootMethodState->mMethodInstance->mMethodInfoEx != NULL) + if ((rootMethodState->mMethodInstance != NULL) && (rootMethodState->mMethodInstance->mMethodInfoEx != NULL)) sanitizedMethodGenericArguments = rootMethodState->mMethodInstance->mMethodInfoEx->mMethodGenericArguments; } else @@ -21677,11 +21680,14 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool // over the local method each time auto rootMethodInstance = prevMethodState.mPrevVal->GetRootMethodState()->mMethodInstance; dependentGenericStartIdx = 0; - if (rootMethodInstance->mMethodInfoEx != NULL) - dependentGenericStartIdx = (int)rootMethodInstance->mMethodInfoEx->mMethodGenericArguments.size(); + if (rootMethodInstance != NULL) + { + if (rootMethodInstance->mMethodInfoEx != NULL) + dependentGenericStartIdx = (int)rootMethodInstance->mMethodInfoEx->mMethodGenericArguments.size(); - methodInstance->mIsUnspecialized = rootMethodInstance->mIsUnspecialized; - methodInstance->mIsUnspecializedVariation = rootMethodInstance->mIsUnspecializedVariation; + methodInstance->mIsUnspecialized = rootMethodInstance->mIsUnspecialized; + methodInstance->mIsUnspecializedVariation = rootMethodInstance->mIsUnspecializedVariation; + } } for (int genericArgIdx = dependentGenericStartIdx; genericArgIdx < (int) methodInstance->GetNumGenericArguments(); genericArgIdx++)