Skip to content

Commit

Permalink
Fix issue with Null<> wrapped and non-null wrapped unification of typ…
Browse files Browse the repository at this point in the history
…eParameters
  • Loading branch information
m0rkeulv committed Sep 1, 2024
1 parent 78ca4e6 commit 8672704
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,8 @@ static ResultHolder handleCallExpression(
}
if (functionType instanceof SpecificFunctionReference ftype) {

ResultHolder returnType = ftype.getReturnType().tryUnwrapNullType();
ResultHolder returnType = ftype.getReturnType();
boolean nullWrapped = returnType.isNullWrappedType();

HaxeGenericResolver functionResolver = new HaxeGenericResolver();
functionResolver.addAll(resolver.withoutArgumentType());
Expand All @@ -1363,8 +1364,9 @@ static ResultHolder handleCallExpression(
functionResolver.addAll(validation.getResolver());
}

ResultHolder resolved = functionResolver.resolveReturnType(returnType);
ResultHolder resolved = functionResolver.resolveReturnType(returnType.tryUnwrapNullType());
if (resolved != null && !resolved.isUnknown()) {
if(nullWrapped) resolved = resolved.wrapInNullType();
returnType = resolved;
}
if(returnType.isUnknown() || returnType.isDynamic() || returnType.isVoid()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,21 @@ static public SpecificTypeReference unify(SpecificTypeReference a, SpecificTypeR
if ((a.isDynamic() || a.isExpr()) && constantIsNullValue(a) && !b.isUnknown()) return b;
if ((b.isDynamic() || b.isExpr()) && constantIsNullValue(b) && !a.isUnknown()) return a;

boolean isNullWrapped = a.isNullType() || b.isNullType();
SpecificTypeReference referenceA = a.isNullType() ? ((SpecificHaxeClassReference)a).unwrapNullType() : a;
SpecificTypeReference referenceB = b.isNullType() ? ((SpecificHaxeClassReference)b).unwrapNullType() : b;

if (a instanceof SpecificHaxeClassReference && b instanceof SpecificHaxeClassReference) {
if (referenceA instanceof SpecificHaxeClassReference classReferenceA && referenceB instanceof SpecificHaxeClassReference classReferenceB) {

if (suggestedType instanceof SpecificHaxeClassReference suggestedClassReference) {
SpecificTypeReference reference = unifyTypes(suggestedClassReference, (SpecificHaxeClassReference)a, context, rules);
reference = unifyTypes((SpecificHaxeClassReference)reference, (SpecificHaxeClassReference)b, context, rules);
SpecificTypeReference reference = unifyTypes(suggestedClassReference, classReferenceA, context, rules);
reference = unifyTypes((SpecificHaxeClassReference)reference, classReferenceB, context, rules);
if (!reference.isUnknown()) {
return reference;
}
}
return unifyTypes((SpecificHaxeClassReference)a, (SpecificHaxeClassReference)b, context, rules);
SpecificTypeReference reference = unifyTypes(classReferenceA, classReferenceB, context, rules);
return isNullWrapped? reference.wrapInNullType() : reference;
}
if (a instanceof SpecificFunctionReference && b instanceof SpecificFunctionReference) {
// TODO suggested type support for functions
Expand Down Expand Up @@ -165,6 +169,21 @@ static public SpecificTypeReference unifyTypes(SpecificHaxeClassReference a, Spe
if (a.getHaxeClassModel() == null) return SpecificTypeReference.getDynamic(context);
if (b.getHaxeClassModel() == null) return SpecificTypeReference.getDynamic(context);

// if not same type but typedef, resolve typdefs and try to unify real type
if (!a.isSameType(b) && (a.isTypeDef() || b.isTypeDef())) {
SpecificTypeReference referenceA = a;
SpecificTypeReference referenceB = b;
if (a.isTypeDef()) {
referenceA = a.fullyResolveTypeDefReference();
}
if (b.isTypeDef()) {
referenceB = b.fullyResolveTypeDefReference();
}
if (referenceA != null && referenceB != null) {
return unify(referenceA, referenceB, context, rules);
}
}

@NotNull ResultHolder[] specificsA = a.getSpecifics();
@NotNull ResultHolder[] specificsB = b.getSpecifics();
if (a.isSameType(b)) {
Expand Down

0 comments on commit 8672704

Please sign in to comment.