Constants access priority

This commit is contained in:
aNNiMON 2023-09-17 18:49:18 +03:00 committed by Victor Melnik
parent cdf0219ca1
commit f6c3f3fe17
2 changed files with 12 additions and 6 deletions

View File

@ -76,12 +76,19 @@ public final class ScopeHandler {
public static boolean isVariableOrConstantExists(String name) { public static boolean isVariableOrConstantExists(String name) {
if (rootScope().containsConstant(name)) {
return true;
}
synchronized (lock) { synchronized (lock) {
return findScope(name).isFound; return findScope(name).isFound;
} }
} }
public static Value getVariableOrConstant(String name) { public static Value getVariableOrConstant(String name) {
Value constant = rootScope().getConstant(name);
if (constant != null) {
return constant;
}
synchronized (lock) { synchronized (lock) {
final ScopeFindData scopeData = findScope(name); final ScopeFindData scopeData = findScope(name);
if (scopeData.isFound) { if (scopeData.isFound) {

View File

@ -44,13 +44,12 @@ public final class MatchExpression extends InterruptableNode implements Expressi
return evalResult(p.result); return evalResult(p.result);
} }
} else { } else {
try (final var ignored = ScopeHandler.closeableScope()) {
ScopeHandler.defineVariableInCurrentScope(pattern.variable, value); ScopeHandler.defineVariableInCurrentScope(pattern.variable, value);
if (optMatches(p)) { if (optMatches(p)) {
final Value result = evalResult(p.result); return evalResult(p.result);
ScopeHandler.removeVariable(pattern.variable); }
return result;
} }
ScopeHandler.removeVariable(pattern.variable);
} }
} }
if ((value.type() == Types.ARRAY) && (p instanceof ListPattern pattern)) { if ((value.type() == Types.ARRAY) && (p instanceof ListPattern pattern)) {