@@ -703,10 +703,15 @@ static void CollectFunctionData(ref List<ReCTFunction> functions, ref List<ReCTG
703703 List < ReCTVariable > variables = new List < ReCTVariable > ( ) ;
704704 List < ReCTVariable > parameters = new List < ReCTVariable > ( ) ;
705705
706- if ( fnc . scope != null )
706+ //if (fnc.scope != null)
707+ //{
708+ // foreach(var vr in fnc.scope.GetDeclaredVariables())
709+ // CollectVariableData(ref variables, ref globals, vr);
710+ //}
711+
712+ if ( fnc . block != null )
707713 {
708- foreach ( var vr in fnc . scope . GetDeclaredVariables ( ) )
709- CollectVariableData ( ref variables , ref globals , vr ) ;
714+ variables . AddRange ( CollectVariablesInBlockRecursively ( fnc . block , ref globals ) ) ;
710715 }
711716
712717 foreach ( var param in fnc . Parameters )
@@ -718,6 +723,23 @@ static void CollectFunctionData(ref List<ReCTFunction> functions, ref List<ReCTG
718723 function . Parameters = parameters . ToArray ( ) ;
719724 functions . Add ( function ) ;
720725 }
726+ static List < ReCTVariable > CollectVariablesInBlockRecursively ( BoundBlockStatement block , ref List < ReCTGlobal > globals )
727+ {
728+ List < ReCTVariable > variables = new List < ReCTVariable > ( ) ;
729+
730+ if ( block . Scope == null ) return variables ;
731+
732+ foreach ( var vr in block . Scope . GetDeclaredVariables ( ) )
733+ CollectVariableData ( ref variables , ref globals , vr ) ;
734+
735+ foreach ( var statement in block . Statements )
736+ if ( statement is BoundBlockStatement newBlock )
737+ {
738+ variables . AddRange ( CollectVariablesInBlockRecursively ( newBlock , ref globals ) ) ;
739+ }
740+
741+ return variables ;
742+ }
721743
722744 static void CollectClassData ( ref List < ReCTClass > classes , ref List < ReCTGlobal > globals , ClassSymbol cls )
723745 {
0 commit comments