Skip to content

Commit

Permalink
Fix for incorrect returnType resolve when typeParameter constraint wh…
Browse files Browse the repository at this point in the history
…ere present.
  • Loading branch information
m0rkeulv committed Sep 1, 2024
1 parent 50cc850 commit 86c8805
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void check(HaxeAssignExpression psi, AnnotationHolder holder) {
HaxeGenericResolver rhsResolver = HaxeGenericResolverUtil.generateResolverFromScopeParents(rhs);

ResultHolder lhsType = HaxeTypeResolver.getPsiElementType(lhs, psi, lhsResolver);
rhsResolver.add("", lhsType, ResolveSource.ASSIGN_TYPE);
rhsResolver.add("", lhsType.tryUnwrapNullType(), ResolveSource.ASSIGN_TYPE);
// if class add type hinting for resolver
if(lhsType.isClassType()){
SpecificHaxeClassReference type = lhsType.getClassType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,12 @@ public static ResultHolder searchReferencesForType(final HaxeComponentName compo
} else if (!possibleType.isUnknown() && !possibleType.isDynamic()) {
//NOTE: don't use unify here (will break function type from usage)
// we want to search only for more specific types (ex. EnumValue & SomeEnum)
boolean canAssign = lastValue.canAssign(possibleType);
if (canAssign) lastValue = possibleType;
if (lastValue.isEnumValueType() || lastValue.isFunctionType()) {
boolean canAssign = lastValue.canAssign(possibleType);
if (canAssign) lastValue = possibleType;
}else {
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,30 +1228,10 @@ static ResultHolder handleCallExpression(
HaxeGenericResolver resolver,
HaxeCallExpression callExpression) {
HaxeExpression callExpressionRef = callExpression.getExpression();

HaxeGenericResolver localResolver = new HaxeGenericResolver();
// generateResolverFromScopeParents - making sure we got typeParameters from arguments/parameters
HaxeGenericResolver localResolver = HaxeGenericResolverUtil.generateResolverFromScopeParents(callExpression);
localResolver.addAll(resolver);
ResultHolder callie = tryGetCallieType(callExpression);

if (callie != null && callie.getClassType() != null && callie.getClassType().isNullType()) {
callie = callie.getClassType().unwrapNullType().createHolder();
}
// TODO should we resolve callie if callie is typeParam ?

HaxeGenericResolver resolverForMethodDeclaringClass = new HaxeGenericResolver();
if (callie != null && !callie.isUnknown() && !callie.isTypeParameter() ) {
if (callExpression.getExpression() instanceof HaxeReferenceExpression referenceExpression) {
PsiElement resolve = referenceExpression.resolve();
if (resolve instanceof HaxeMethodDeclaration methodDeclaration) {
HaxeClassModel aClass = methodDeclaration.getModel().getDeclaringClass();
SpecificHaxeClassReference type = callie.getClassType();
if (type != null && type.getHaxeClass() != null) {
resolverForMethodDeclaringClass = createInheritedClassResolver(aClass.haxeClass, type.getHaxeClass(), resolverForMethodDeclaringClass);
localResolver.addAll(resolverForMethodDeclaringClass);
}
}
}
}

SpecificTypeReference functionType = handle(callExpressionRef, context, localResolver).getType();
boolean varIsMacroFunction = isCallExpressionToMacroMethod(callExpressionRef);
boolean callIsFromMacroContext = isInMacroFunction(callExpressionRef);
Expand Down

0 comments on commit 86c8805

Please sign in to comment.