Skip to content

Commit

Permalink
avoid check usage when type is known for Literal Array
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Oct 27, 2023
1 parent fbaf60d commit a65913d
Showing 1 changed file with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1028,25 +1028,28 @@ else if (subelement instanceof AbstractHaxeNamedComponent namedComponent) {
}
}
}

ResultHolder elementTypeHolder = references.isEmpty()
? SpecificTypeReference.getUnknown(element).createHolder()
: HaxeTypeUnifier.unify(references, element, suggestedType).withoutConstantValue().createHolder();

SpecificTypeReference result = SpecificHaxeClassReference.createArray(elementTypeHolder, element);
if (allConstants) result = result.withConstantValue(constants);
ResultHolder holder = result.createHolder();

// try to resolve typeParameter when we got empty literal array with declaration without typeTag
if (elementTypeHolder.isUnknown()) {
HaxePsiField declaringField = PsiTreeUtil.getParentOfType(element, HaxePsiField.class);
if (declaringField != null) {
ResultHolder searchResult = searchReferencesForTypeParameters(declaringField, context, resolver, holder);
if (!searchResult.isUnknown()) holder = searchResult;
// empty expression with type tag (var x:Array<T> = []), no need to look for usage
if (references.isEmpty() && suggestedType != null && !suggestedType.isUnknown()) {
return SpecificHaxeClassReference.createArray(suggestedType.createHolder(), element).createHolder();
} else {
ResultHolder elementTypeHolder = references.isEmpty()
? SpecificTypeReference.getUnknown(element).createHolder()
: HaxeTypeUnifier.unify(references, element, suggestedType).withoutConstantValue().createHolder();

SpecificTypeReference result = SpecificHaxeClassReference.createArray(elementTypeHolder, element);
if (allConstants) result = result.withConstantValue(constants);
ResultHolder holder = result.createHolder();

// try to resolve typeParameter when we got empty literal array with declaration without typeTag
if (elementTypeHolder.isUnknown()) {
HaxePsiField declaringField = PsiTreeUtil.getParentOfType(element, HaxePsiField.class);
if (declaringField != null) {
ResultHolder searchResult = searchReferencesForTypeParameters(declaringField, context, resolver, holder);
if (!searchResult.isUnknown()) holder = searchResult;
}
}
}

return holder;
}
}

if (element instanceof HaxePsiToken psiToken) {
Expand Down

0 comments on commit a65913d

Please sign in to comment.