Skip to content

Commit

Permalink
Fix a bug with scopes in patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
valis committed Aug 31, 2023
1 parent 58e3bc4 commit 01f21bd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions base/src/main/java/org/arend/naming/scope/ScopeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,24 @@ public static Scope forSourceNode(Scope parentScope, Abstract.SourceNode sourceN
return new PatternScope(parentScope, ((Abstract.Clause) parentSourceNode).getPatterns());
}

// Extend the scope with previous patterns for the type in a pattern
if (sourceNode instanceof Abstract.Expression && parentSourceNode instanceof Abstract.Pattern) {
Abstract.SourceNode parentParentSourceNode = parentSourceNode.getParentSourceNode();
List<? extends Abstract.Pattern> patterns = parentParentSourceNode instanceof Abstract.Clause clause ? clause.getPatterns() : parentParentSourceNode instanceof Abstract.Pattern pattern ? pattern.getSequence() : Collections.emptyList();
if (!patterns.isEmpty()) {
List<Abstract.Pattern> newPatterns = new ArrayList<>(patterns.size());
for (Abstract.Pattern pattern : patterns) {
if (pattern == parentSourceNode) {
break;
}
newPatterns.add(pattern);
}
if (!newPatterns.isEmpty()) {
return new PatternScope(parentScope, newPatterns);
}
}
}

return parentScope;
}
}

0 comments on commit 01f21bd

Please sign in to comment.