Skip to content

Commit

Permalink
resolve type from usage for empty array init with no typetag (`var v …
Browse files Browse the repository at this point in the history
…= []; v[0]="s";`)
  • Loading branch information
m0rkeulv committed Oct 23, 2023
1 parent 2b3c821 commit 030781e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ else if (expression instanceof HaxeExtractorMatchExpression matchExpression) {
}

/*
HaxeExtractorMatchExpression can be chained so we need to loop until we get a refrence
HaxeExtractorMatchExpression can be chained so we need to loop until we get a reference
ex. case add(_, 1) => mul(_1, 3) => a:
*/
private HaxeReferenceExpression getReferenceFromExtractorMatchExpression(HaxeExtractorMatchExpression expression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ static private ResultHolder _handle(final PsiElement element,
HaxePsiField fieldDeclaration = PsiTreeUtil.getParentOfType(expression, HaxePsiField.class);
if (fieldDeclaration != null && fieldDeclaration.getTypeTag() == null) {
SpecificHaxeClassReference classType = typeHolder.getClassType();
// if class does not have any generics there no need to search for refrences
// if class does not have any generics there no need to search for references
if (classType != null && classType.getSpecifics().length > 0) {
ResultHolder searchResult = searchReferencesForTypeParameters(fieldDeclaration, context, resolver, typeHolder);
if (!searchResult.isUnknown()) {
Expand Down Expand Up @@ -987,6 +987,16 @@ else if (subelement instanceof AbstractHaxeNamedComponent namedComponent) {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,6 @@ else if (from.isUnknown()) {
return canAssignToFrom(to.getType(), from.getType(), true, to.getOrigin(), from.getOrigin());
}

//TODO mlo, hack to allow macro expressions to assign to anything
// thoughts: ExprOf<T> might be mapped to T when only one part of the assignment is macro
private static boolean isMacroExpression(ResultHolder from) {
SpecificHaxeClassReference type = from.getClassType();
if (type != null && type.getHaxeClass() != null) {
String qualifiedName = type.getHaxeClass().getQualifiedName();
return switch (qualifiedName) {
case "haxe.macro.Expr" -> true;
case "haxe.macro.ExprOf" -> true;
default -> false;
};
}
return false;
}



static private boolean isFunctionTypeOrReference(SpecificTypeReference ref) {
return ref instanceof SpecificFunctionReference
Expand Down

0 comments on commit 030781e

Please sign in to comment.