Skip to content

Commit

Permalink
"hack" to get generic resolver from call expression when trying to re…
Browse files Browse the repository at this point in the history
…solve parameter type
  • Loading branch information
m0rkeulv committed Mar 25, 2024
1 parent be185ab commit 417c798
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog
## 1.4.47
* Fixed: attempt at fixing incorrect sorting of Project roots
*
* Improvement: Better type resolve for parameters without type tag in functionLiterals


## 1.4.46
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,21 @@ public static ResultHolder tryToFindTypeFromCallExpression(HaxeFunctionLiteral l
int parameterMappedToArgument = parameterList.getParameterList().indexOf(parameter);
List<SpecificFunctionReference.Argument> arguments = functionType.getArguments();
SpecificFunctionReference.Argument argument = arguments.get(parameterMappedToArgument);

HaxeGenericResolver parentExpResolver = getGenericResolverFromParentExpression(callExpression);
// this is an ugly hack to get a resolver from callexpression without causing a stack overflow as this parameter could be
// a type parameter that the resolver needs to resolve, if we notice that we are resolving multiple times we try to only use
// parent genericResolver values or allow this second pass to return unknown so that any other parameters can populate
// the generic resolver
HaxeGenericResolver parentExpResolver = null;
try {
if (genericResolverHelper.get() == callExpression) {
parentExpResolver = getGenericResolverFromParentExpression(callExpression);
}else {
genericResolverHelper.set(callExpression);
parentExpResolver = HaxeGenericResolverUtil.generateResolverFromScopeParents(callExpression);
}
}finally{
genericResolverHelper.remove();
}
ResultHolder resolved = parentExpResolver.resolve(argument.getType());
if (resolved != null && !resolved.isUnknown()) return resolved.getType().createHolder();

Expand All @@ -950,6 +963,7 @@ public static ResultHolder tryToFindTypeFromCallExpression(HaxeFunctionLiteral l
}
return null;
}
private static ThreadLocal<HaxeCallExpression> genericResolverHelper = new ThreadLocal<>();

private static HaxeGenericResolver getGenericResolverFromParentExpression(HaxeCallExpression callExpression) {
@NotNull PsiElement[] children = callExpression.getChildren();
Expand Down

0 comments on commit 417c798

Please sign in to comment.