Skip to content

Commit

Permalink
HidesVariableCheck now allows for variable definition in ancestor sco…
Browse files Browse the repository at this point in the history
…pe, when defined at lower line
  • Loading branch information
StevenLooman committed Jul 29, 2023
1 parent 1e2ab35 commit b8dfd1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import nl.ramsolutions.sw.magik.analysis.scope.GlobalScope;
import nl.ramsolutions.sw.magik.analysis.scope.Scope;
import nl.ramsolutions.sw.magik.analysis.scope.ScopeEntry;
import nl.ramsolutions.sw.magik.analysis.scope.ScopeEntry.Type;
import nl.ramsolutions.sw.magik.api.MagikGrammar;
import nl.ramsolutions.sw.magik.api.MagikKeyword;
import nl.ramsolutions.sw.magik.checks.MagikCheck;
Expand Down Expand Up @@ -66,7 +65,8 @@ private void checkIdentifier(final Scope scope, final AstNode identifierNode) {
for (final Scope ancestorScope : scope.getAncestorScopes()) {
final ScopeEntry scopeEntry = ancestorScope.getScopeEntry(identifier);
if (scopeEntry != null
&& scopeEntry.isType(Type.LOCAL)) {
&& scopeEntry.isType(ScopeEntry.Type.LOCAL)
&& scopeEntry.getNode().getTokenLine() < identifierNode.getTokenLine()) {
this.addIssue(identifierNode, MESSAGE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class HidesVariableCheckTest extends MagikCheckTestBase {
+ " _import a\n"
+ " _endproc\n"
+ "_endblock\n",
""
+ "_block\n"
+ " _block\n"
+ " _local a << 20\n"
+ " _endblock\n"
+ " _local a << 10\n"
+ "_endblock\n",
})
void testValid(final String code) {
final MagikCheck check = new HidesVariableCheck();
Expand Down

0 comments on commit b8dfd1f

Please sign in to comment.