瀏覽代碼

Fixed scope issue for scope-allocated value as switch value

Brian Fiete 5 年之前
父節點
當前提交
97fd278e07
共有 1 個文件被更改,包括 18 次插入9 次删除
  1. 18 9
      IDEHelper/Compiler/BfStmtEvaluator.cpp

+ 18 - 9
IDEHelper/Compiler/BfStmtEvaluator.cpp

@@ -4078,16 +4078,16 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt)
 }
 
 void BfModule::Visit(BfSwitchStatement* switchStmt)
-{	
-	BfScopeData newScope;
-	newScope.mInnerIsConditional = false;
-	newScope.mCloseNode = switchStmt;
+{
+	BfScopeData outerScope;
+	outerScope.mInnerIsConditional = false;
+	outerScope.mCloseNode = switchStmt;
 	if (switchStmt->mCloseBrace != NULL)
-		newScope.mCloseNode = switchStmt->mCloseBrace;
+		outerScope.mCloseNode = switchStmt->mCloseBrace;
 	if (switchStmt->mLabelNode != NULL)
-		newScope.mLabelNode = switchStmt->mLabelNode->mLabel;		
-	mCurMethodState->AddScope(&newScope);	
-	NewScopeState();	
+		outerScope.mLabelNode = switchStmt->mLabelNode->mLabel;
+	mCurMethodState->AddScope(&outerScope);
+	NewScopeState();
 
 	auto valueScopeStartOuter = ValueScopeStart();
 
@@ -4124,7 +4124,15 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
 	}
 
 	// We make the switch value conditional, but all other uses of this scope is conditional since it's conditional on cases
+	BfScopeData newScope;
 	newScope.mInnerIsConditional = true;
+	newScope.mCloseNode = switchStmt;
+	if (switchStmt->mCloseBrace != NULL)
+		newScope.mCloseNode = switchStmt->mCloseBrace;
+	if (switchStmt->mLabelNode != NULL)
+		newScope.mLabelNode = switchStmt->mLabelNode->mLabel;
+	mCurMethodState->AddScope(&newScope);
+	NewScopeState();	
 	
 	BfTypedValue switchValueAddr = switchValue;
 	
@@ -4869,7 +4877,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
 			lifetimeExtendVal = localDef->mValue;					
 	}
 	
-	RestoreScopeState();
+	RestoreScopeState(); // newScope
+	RestoreScopeState(); // outerScope
 
 	if (lifetimeExtendVal)
 		mBfIRBuilder->CreateLifetimeExtend(lifetimeExtendVal);