Skip to content

Commit

Permalink
Fixing type resolve for inline method calls (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Aug 19, 2023
1 parent 7c0bfa7 commit 3fcfe64
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.4.13
* Added: Quick fix for incorrect extends and implements (#940)
* Fixed: Resolving type from inline method calls (#868)

## 1.4.12
* Bugfix: "import class quickfix" missing in some cases (#1132)
* Bugfix: "Find Usages" was not checking catch blocks correctly(#929)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ else if (element instanceof HaxeLocalVarDeclaration varDeclaration) {
if (valueExpression.getVarInit() != null){
return handle(valueExpression.getVarInit(), context, resolver);
}
if (valueExpression.getExpression() != null){
return handle(valueExpression.getExpression(), context, resolver);
}
}

if (element instanceof HaxeReferenceExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.stream.Stream;

import static com.intellij.plugins.haxe.lang.lexer.HaxeTokenTypeSets.DOC_COMMENT;
import static com.intellij.plugins.haxe.model.type.HaxeExpressionEvaluator.evaluate;
import static com.intellij.plugins.haxe.util.HaxeDebugLogUtil.traceAs;

/**
Expand Down Expand Up @@ -751,9 +752,46 @@ private static HaxeResolveResult getHaxeClassResolveResultInternal(@Nullable Psi
result.specialize(initExpression);
return result;
}

if (element instanceof HaxeValueExpression valueExpression) {
result = resolveValueExpressionClass(valueExpression, specialization);
if (result != null) {
return result;
}
}

return getHaxeClassResolveResult(initExpression, specialization);
}

private static HaxeResolveResult resolveValueExpressionClass(HaxeValueExpression valueExpression,
@Nullable HaxeGenericSpecialization specialization) {

HaxePsiCompositeElement element = null;
if (valueExpression.getSwitchStatement() != null) {
element = valueExpression.getSwitchStatement();
}
if (valueExpression.getIfStatement() != null) {
element = valueExpression.getIfStatement();
}
if (valueExpression.getTryStatement() != null) {
element = valueExpression.getTryStatement();
}
if (valueExpression.getVarInit() != null) {
element = valueExpression.getVarInit();
}
if (valueExpression.getExpression() != null) {
element = valueExpression.getExpression();

}

HaxeExpressionEvaluatorContext context = new HaxeExpressionEvaluatorContext(element);
ResultHolder result = evaluate(element, context, specialization.toGenericResolver(valueExpression)).result;
if (result.getClassType() != null) {
return result.getClassType().asResolveResult();
}
return null;
}

private static HaxeResolveResult searchForIterableTypeRecursively(HaxeResolveResult resolveResult,
List<String> circularReferenceProtection) {
final HaxeClass resolveResultHaxeClass = resolveResult.getHaxeClass();
Expand Down Expand Up @@ -1247,7 +1285,7 @@ public static SpecificHaxeClassReference resolveExtractorEnum(HaxeEnumArgumentEx
expression = parenthesizedExpression.getExpression();
}
HaxeGenericResolver resolver = HaxeGenericResolverUtil.generateResolverFromScopeParents(expression);
ResultHolder result = HaxeExpressionEvaluator.evaluate(expression, new HaxeExpressionEvaluatorContext(expression), resolver).result;
ResultHolder result = evaluate(expression, new HaxeExpressionEvaluatorContext(expression), resolver).result;
// null type "hack" : if nullType unwrap to real type
if(result.getType().isNullType()) {
result = result.getClassType().getSpecifics()[0];
Expand Down

0 comments on commit 3fcfe64

Please sign in to comment.