Skip to content

Commit 5adffea

Browse files
committed
Attempting to remedy stack overflow issue
1 parent 9108c05 commit 5adffea

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Changelog
2+
## 1.4.43
3+
* Adding overflow guard when converting GenericSpecialization to genericResolver
24
## 1.4.42
35
* Bugfix: Function bindings was incorrectly treated as static extensions
46
* Bugfix: Stack overflow when resolving expression type

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pluginName = Haxe Toolkit Support
77
pluginRepositoryUrl = https://github.com/HaxeFoundation/intellij-haxe
88

99
# SemVer format -> https://semver.org
10-
pluginVersion = 1.4.42
10+
pluginVersion = 1.4.43
1111

1212
# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
1313
platformType = IU

src/main/java/com/intellij/plugins/haxe/lang/psi/HaxeGenericSpecialization.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@
2424
import com.intellij.plugins.haxe.util.HaxeResolveUtil;
2525
import com.intellij.psi.PsiElement;
2626
import com.intellij.psi.util.PsiTreeUtil;
27+
import lombok.CustomLog;
2728
import org.jetbrains.annotations.NotNull;
2829
import org.jetbrains.annotations.Nullable;
2930

3031
import java.util.LinkedHashMap;
3132
import java.util.Map;
3233
import java.util.Objects;
34+
import java.util.Stack;
3335

3436
/**
3537
* @author: Fedor.Korotkov
3638
*/
39+
@CustomLog
3740
public class HaxeGenericSpecialization implements Cloneable {
3841

3942
public static final HaxeGenericSpecialization EMPTY = new HaxeGenericSpecialization() {
@@ -80,6 +83,10 @@ protected HaxeGenericSpecialization(LinkedHashMap<String, HaxeResolveResult> map
8083
this.map = map;
8184
}
8285

86+
// TODO: temp workaround to stop overflow issue in closed source (have not yet found way to reproduce)
87+
// it seems to be related to function types and resolving type parameters?
88+
private static ThreadLocal<Stack<PsiElement>> referencesProcessing = ThreadLocal.withInitial(Stack::new);
89+
8390
/**
8491
* @return the values in this specialization as a HaxeGenericResolver.
8592
**/
@@ -93,6 +100,7 @@ public HaxeGenericResolver toGenericResolver(@Nullable PsiElement element) {
93100
*
94101
* A third would be to remove HaxeGenericResolver altogether and make the models use this class.
95102
*/
103+
Stack<PsiElement> elements = referencesProcessing.get();
96104
if (null == element) {
97105
element = SpecificTypeReference.createUnknownContext();
98106
}
@@ -103,21 +111,43 @@ public HaxeGenericResolver toGenericResolver(@Nullable PsiElement element) {
103111
for (String key : innerMap.keySet()) {
104112
HaxeResolveResult resolveResult = innerMap.get(key);
105113

106-
ResultHolder resultHolder;
114+
ResultHolder resultHolder = null;
115+
107116
if (resolveResult.isFunctionType()) {
108117
HaxeFunctionType functionType = resolveResult.getFunctionType();
109-
resultHolder = resolveResult.getSpecificFunctionReference(functionType, null).createHolder();
110-
}else if (resolveResult.isHaxeClass()) {
118+
if (!elements.contains(functionType)) {
119+
try {
120+
elements.add(functionType);
121+
resultHolder = resolveResult.getSpecificFunctionReference(functionType, null).createHolder();
122+
} finally {
123+
elements.pop();
124+
}
125+
}else {
126+
log.warn("Overflow prevention");
127+
}
128+
}
129+
else if (resolveResult.isHaxeClass()) {
111130
HaxeClass haxeClass = resolveResult.getHaxeClass();
112-
resultHolder = resolveResult.getSpecificClassReference(haxeClass, null).createHolder();
113-
}else {
131+
if (!elements.contains(haxeClass)) {
132+
try {
133+
elements.add(haxeClass);
134+
resultHolder = resolveResult.getSpecificClassReference(haxeClass, null).createHolder();
135+
} finally {
136+
elements.pop();
137+
}
138+
}else {
139+
log.warn("Overflow prevention");
140+
}
141+
}
142+
if (resultHolder == null) {
114143
HaxeClass haxeClass = SpecificHaxeClassReference.getUnknown(element).getHaxeClass();
115144
resultHolder = resolveResult.getSpecificClassReference(haxeClass, null).createHolder();
116145
}
117146

118147
resolver.add(key, resultHolder, ResolveSource.CLASS_TYPE_PARAMETER);
119148
}
120149
return resolver;
150+
121151
}
122152

123153
@NotNull

0 commit comments

Comments
 (0)