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

Fixed some places where variable declarations should be illegal

This commit is contained in:
Brian Fiete 2020-05-07 11:02:39 -07:00
parent 26604017f8
commit b128180a15
4 changed files with 18 additions and 4 deletions

View file

@ -2457,6 +2457,16 @@ void BfExprEvaluator::Visit(BfVariableDeclaration* varDecl)
{
mModule->UpdateExprSrcPos(varDecl);
if ((mModule->mCurMethodState == NULL) || (!mModule->mCurMethodState->mCurScope->mAllowVariableDeclarations))
{
mModule->Fail("Variable declarations are not allowed in this context", varDecl);
if (varDecl->mInitializer != NULL)
{
VisitChild(varDecl->mInitializer);
}
return;
}
CheckVariableDeclaration(varDecl, true, false, false);
if (varDecl->mInitializer == NULL)
{
@ -5017,6 +5027,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
// Temporarily disable so we don't capture calls in params
SetAndRestoreValue<BfFunctionBindResult*> prevBindResult(mFunctionBindResult, NULL);
SetAndRestoreValue<bool> prevAllowVariableDeclarations(mModule->mCurMethodState->mCurScope->mAllowVariableDeclarations, false); // Don't allow variable declarations in arguments
BfMethodInstance* methodInstance = moduleMethodInstance.mMethodInstance;
@ -5827,7 +5838,7 @@ BfTypedValue BfExprEvaluator::ResolveArgValue(BfResolvedArg& resolvedArg, BfType
{
BfExprEvaluator exprEvaluator(mModule);
exprEvaluator.mReceivingValue = receivingValue;
BfEvalExprFlags flags = BfEvalExprFlags_NoCast;
BfEvalExprFlags flags = (BfEvalExprFlags)(BfEvalExprFlags_NoCast);
if ((paramKind == BfParamKind_Params) || (paramKind == BfParamKind_DelegateParam))
flags = (BfEvalExprFlags)(flags | BfEvalExprFlags_AllowParamsExpr);
@ -6154,6 +6165,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
// Temporarily disable so we don't capture calls in params
SetAndRestoreValue<BfFunctionBindResult*> prevBindResult(mFunctionBindResult, NULL);
SetAndRestoreValue<bool> prevAllowVariableDeclarations(mModule->mCurMethodState->mCurScope->mAllowVariableDeclarations, false); // Don't allow variable declarations in arguments
sInvocationIdx++;

View file

@ -314,6 +314,7 @@ public:
bool mAllowTargeting;
bool mHadScopeValueRetain;
bool mIsDeferredBlock;
bool mAllowVariableDeclarations;
BfBlock* mAstBlock;
BfAstNode* mCloseNode;
BfExprEvaluator* mExprEvaluator;
@ -346,6 +347,7 @@ public:
mHadScopeValueRetain = false;
mIsDeferredBlock = false;
mAllowTargeting = true;
mAllowVariableDeclarations = true;
mMixinDepth = 0;
mScopeDepth = 0;
}