Skip to content

Commit c66bf06

Browse files
Simplify ScriptLoader scope freezing logic
1 parent 7ee2318 commit c66bf06

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/main/java/ch/njol/skript/ScriptLoader.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,11 @@ public static ArrayList<TriggerItem> loadItems(SectionNode node) {
953953

954954
// Begin local variable type hints
955955
parser.getHintManager().enterScope();
956-
boolean freezeHints = false;
956+
// Track if the scope has been frozen
957+
// This is the case when a statement that stops further execution is encountered
958+
// Further statements would not run, meaning the hints from them are inaccurate
959+
// When true, before exiting the scope, its hints are cleared to avoid passing them up
960+
boolean freezeScope = false;
957961

958962
boolean executionStops = false;
959963
for (Node subNode : node) {
@@ -1038,31 +1042,19 @@ public static ArrayList<TriggerItem> loadItems(SectionNode node) {
10381042
}
10391043
executionStops = item.executionIntent() != null;
10401044

1041-
if (executionStops && !freezeHints) {
1042-
freezeHints = true;
1043-
1044-
// If we are exiting multiple sections, hints should instead be copied to the section we are exiting to
1045-
// Exiting only one section does not require special behavior
1046-
if (item.executionIntent() instanceof ExecutionIntent.StopSections intent && intent.levels() > 1) {
1045+
if (executionStops && !freezeScope) {
1046+
freezeScope = true;
1047+
// Execution might stop for some sections but not all
1048+
// We want to pass hints up to the scope that execution resumes in
1049+
if (item.executionIntent() instanceof ExecutionIntent.StopSections intent) {
10471050
parser.getHintManager().mergeScope(0, intent.levels());
1048-
parser.getHintManager().enterScope(); // Enter a new scope to capture all new type hints
1049-
// Clear scope to prevent duplicate copying
1050-
// We clear after entering the capturing scope so that the capturing scope still has hints
1051-
parser.getHintManager().clearScope(1);
1052-
} else {
1053-
parser.getHintManager().enterScope(); // Enter a new scope to capture all new type hints
10541051
}
10551052
}
10561053
}
10571054

1058-
// If hints were frozen, then we need to destroy the scope in which they were captured
1059-
if (freezeHints) {
1060-
parser.getHintManager().clearScope(0); // Clear scope to prevent copying upon exit
1061-
parser.getHintManager().exitScope();
1062-
}
1063-
// If the previous section contains a statement that stops the trigger, then any type hints
1064-
// provided by the section are not useful. Thus, we clear them.
1065-
if (items.stream().anyMatch(item -> item.executionIntent() instanceof ExecutionIntent.StopTrigger)) {
1055+
// If the scope was frozen, then we need to clear it to prevent passing up inaccurate hints
1056+
// They will have already been copied as necessary
1057+
if (freezeScope) {
10661058
parser.getHintManager().clearScope(0);
10671059
}
10681060
// Destroy local variable type hints for this section

0 commit comments

Comments
 (0)