@@ -347,6 +347,17 @@ predicate bindingContext = LocalNameBindingInput::bindingContext/3;
347347
348348module LocalNameBindingOutput = LocalNameBinding< Location , LocalNameBindingInput > ;
349349
350+ private LocalNameBindingOutput:: Local resolveId ( Identifier id ) {
351+ // For names in binding position, always resolve to the scope set by the bindingContext predicate
352+ exists ( AstNode scope |
353+ bindingContext ( id , scope , _) and
354+ result .hasNameAndScope ( id .getValue ( ) , scope )
355+ )
356+ or
357+ not bindingContext ( id , _, _) and
358+ result = id .( LocalNameBindingOutput:: LocalAccess ) .getLocal ( )
359+ }
360+
350361module Public {
351362 /**
352363 * A representative for a lexically scoped entity, such as a local variable, type name, or module name.
@@ -379,7 +390,7 @@ module Public {
379390 string getName ( ) { result = this .getValue ( ) }
380391
381392 /** Gets the representative for the local name introduced by this declaration. */
382- LocalName getLocalName ( ) { result = this . ( LocalNameBindingOutput :: LocalAccess ) . getLocal ( ) }
393+ LocalName getLocalName ( ) { result = resolveId ( this ) }
383394 }
384395
385396 final class LocalVariable = LocalVariableImpl ;
@@ -495,7 +506,7 @@ module Public {
495506 */
496507class PotentialLocalNameAccess extends IdentifierExpr {
497508 /** Gets the representative for the local name being accessed. */
498- LocalName getLocalName ( ) { result = this . ( LocalNameBindingOutput :: LocalAccess ) . getLocal ( ) }
509+ LocalName getLocalName ( ) { result = resolveId ( this ) }
499510
500511 /** Gets the name being accessed. */
501512 string getName ( ) { result = this .getValue ( ) }
0 commit comments