Skip to content

Commit

Permalink
Fix issue 3631 NameExpr.resolve() does not take end of inner block sc…
Browse files Browse the repository at this point in the history
…opes into account
  • Loading branch information
jlerbsc committed Jul 8, 2022
1 parent e0eb2dc commit 5a58cf3
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@ private SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String n
ListIterator<Statement> statementListIterator = nodeWithStmt.getStatements().listIterator(position);
while(statementListIterator.hasPrevious()) {
Context prevContext = JavaParserFactory.getContext(statementListIterator.previous(), typeSolver);
if (prevContext instanceof BlockStmtContext) {
// Issue #3631
// We have an explicit check for "BlockStmtContext" to avoid resolving the variable x with the
// declaration defined in the block preceding the use of the variable
// For example consider the following:
//
// int x = 0;
// void method() {
// {
// var x = 1;
// System.out.println(x); // prints 1
// }
// System.out.println(x); // prints 0
// }
continue;
}
if (prevContext instanceof StatementContext) {
// We have an explicit check for "StatementContext" to prevent a factorial increase of visited statements.
//
Expand Down

0 comments on commit 5a58cf3

Please sign in to comment.