@@ -239,8 +239,8 @@ public VariablesResult GetVariables(Expression expr, SourceLocation location, st
239239 foreach ( var s in scope . EnumerateTowardsGlobal ) {
240240 var scopeVariables = GetVariablesInScope ( name , s ) . Distinct ( ) ;
241241 variables = variables . Union ( scopeVariables ) ;
242- var args = scopeVariables . Where ( v => IsFunctionArgument ( v . Variable ) ) ;
243- if ( args . Any ( ) ) {
242+ var args = scopeVariables . Where ( v => IsFunctionArgument ( s , v ) ) ;
243+ if ( args . Any ( ) ) {
244244 break ;
245245 }
246246 }
@@ -255,7 +255,7 @@ public VariablesResult GetVariables(Expression expr, SourceLocation location, st
255255 if ( definitions . Length > 0 ) {
256256 var defsToRefs = definitions . Skip ( 1 ) . Select ( v => new AnalysisVariable ( v . Variable , VariableType . Reference , v . Location ) ) ;
257257 variables = definitions . Take ( 1 ) . Concat ( others . Concat ( defsToRefs ) ) ;
258- }
258+ }
259259 }
260260 return new VariablesResult ( variables , unit . Tree ) ;
261261 }
@@ -270,8 +270,17 @@ public VariablesResult GetVariables(Expression expr, SourceLocation location, st
270270 return new VariablesResult ( variables , unit . Tree ) ;
271271 }
272272
273- private bool IsFunctionArgument ( IVariableDefinition v )
274- => v ? . Types ? . MaybeEnumerate ( ) . FirstOrDefault ( ) is ParameterInfo ;
273+ private bool IsFunctionArgument ( IScope scope , IAnalysisVariable v ) {
274+ if ( v . Variable ? . Types ? . MaybeEnumerate ( ) . FirstOrDefault ( ) is ParameterInfo ) {
275+ return true ;
276+ }
277+ if ( scope is FunctionScope funcScope ) {
278+ var def = funcScope . Function . FunctionDefinition ;
279+ // TODO: Use indexes rather than lines to check location
280+ return v . Location . StartLine == def . GetStart ( def . GlobalParent ) . Line ;
281+ }
282+ return false ;
283+ }
275284
276285 private IEnumerable < IAnalysisVariable > GetVariablesInScope ( NameExpression name , IScope scope ) {
277286 var result = new List < IAnalysisVariable > ( ) ;
0 commit comments