diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index b1efdd04..be43ceaf 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -4322,6 +4322,20 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI mModule->FixValueActualization(result); } + if ((mModule->mCurMethodState != NULL) && (mModule->mCurMethodState->mClosureState != NULL) && (findName == "@this")) + { + if (mModule->mCurMethodState->mClosureState->mCapturing) + { + mModule->mCurMethodState->mClosureState->mCapturedDelegateSelf = true; + return mModule->GetDefaultTypedValue(mModule->ResolveTypeDef(mModule->mCompiler->mDelegateTypeDef)); + } + else + { + auto thisLocal = mModule->mCurMethodState->mLocals[0]; + return BfTypedValue(mModule->mBfIRBuilder->CreateLoad(thisLocal->mAddr), thisLocal->mResolvedType); + } + } + return result; } @@ -13606,7 +13620,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam // If we are allowing hot swapping, we need to always mangle the name to non-static because if we add a capture // later then we need to have the mangled names match - methodDef->mIsStatic = (closureTypeInst == NULL) && (!mModule->mCompiler->mOptions.mAllowHotSwapping); + methodDef->mIsStatic = (closureTypeInst == NULL) && (!mModule->mCompiler->mOptions.mAllowHotSwapping) && (!closureState.mCapturedDelegateSelf); SizedArray origParamTypes; BfIRType origReturnType; diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index 889be7e1..53f6a2e1 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/IDEHelper/Compiler/BfModule.h @@ -689,7 +689,8 @@ public: int mCaptureStartAccessId; // When we need to look into another local method to determine captures, but we don't want to process local variable declarations or cause infinite recursion bool mBlindCapturing; - bool mDeclaringMethodIsMutating; + bool mDeclaringMethodIsMutating; + bool mCapturedDelegateSelf; BfReturnTypeInferState mReturnTypeInferState; BfLocalMethod* mLocalMethod; BfClosureInstanceInfo* mClosureInstanceInfo; @@ -714,6 +715,7 @@ public: mCaptureStartAccessId = -1; mBlindCapturing = false; mDeclaringMethodIsMutating = false; + mCapturedDelegateSelf = false; mReturnTypeInferState = BfReturnTypeInferState_None; mActiveDeferredLocalMethod = NULL; mReturnType = NULL;