Skip to content

Commit

Permalink
only show "haxe.unresolved.type" warning for isUnknown() when model =…
Browse files Browse the repository at this point in the history
…= null
  • Loading branch information
m0rkeulv committed Jun 19, 2023
1 parent ad7a457 commit 68245a3
Showing 1 changed file with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.intellij.lang.annotation.*;
import com.intellij.plugins.haxe.HaxeBundle;
import com.intellij.plugins.haxe.HaxeLanguage;
import com.intellij.plugins.haxe.ide.annotator.HaxeSemanticAnnotatorConfig;
import com.intellij.plugins.haxe.lang.psi.*;
import com.intellij.plugins.haxe.model.*;
Expand Down Expand Up @@ -276,10 +275,15 @@ else if (currentParameters.size() != parentParameters.size()) {
// the arguments may not resolve to the same thing. So, we need to resolve the element
// in the super-class before we can check assignment compatibility.
SpecificHaxeClassReference resolvedParent = resolveSuperclassElement(scopeResolver, currentParam, parentParam);
//TODO mlo: Experimental (get constraints from <T:type>method(argsT):T)
HaxeGenericResolver resolverWithConstraints = createGenericResolverFromSignatureConstraints(parentParam);
resolverWithConstraints.addAll(scopeResolver);

// Order of assignment compatibility is to parent, from subclass.
ResultHolder currentParamType = currentParam.getType(scopeResolver);
ResultHolder parentParamType = parentParam.getType(null == resolvedParent ? scopeResolver : resolvedParent.getGenericResolver());
ResultHolder parentParamType = parentParam.getType(null == resolvedParent ? resolverWithConstraints : resolvedParent.getGenericResolver());


if (!canAssignToFrom(parentParamType, currentParamType)) {

typeMismatch(holder, currentParam.getBasePsi(), currentParamType.toString(), parentParamType.toString())
Expand Down Expand Up @@ -340,9 +344,13 @@ public void run() {
if (!canAssignToFrom(parentResult.getType(), currentResult.getType(), holder)) {
PsiElement psi = currentMethod.getReturnTypeTagOrNameOrBasePsi();
if (parentResult.getType().isUnknown()) {
holder.newAnnotation(HighlightSeverity.WEAK_WARNING,HaxeBundle.message("haxe.unresolved.type"))
.range(psi.getTextRange())
.create();
if (parentResult.getType() instanceof SpecificHaxeClassReference classReference) {
if (classReference.getHaxeClassModel() == null) {
holder.newAnnotation(HighlightSeverity.WEAK_WARNING, HaxeBundle.message("haxe.unresolved.type"))
.range(psi.getTextRange())
.create();
}
}
}
else {

Expand All @@ -354,6 +362,18 @@ public void run() {
}
}

@NotNull private static HaxeGenericResolver createGenericResolverFromSignatureConstraints(HaxeParameterModel param) {
HaxeGenericResolver resolver = new HaxeGenericResolver();
if(param.getMemberModel() instanceof HaxeMethodModel methodModel) {
List<HaxeGenericParamModel> params = methodModel.getGenericParams();
for(HaxeGenericParamModel paramModel : params) {
ResultHolder constraint = paramModel.getConstraint(null);
resolver.add(paramModel.getName(), constraint == null ? new ResultHolder(SpecificHaxeClassReference.getDynamic(paramModel.getPsi())) : constraint);
}
}
return resolver;
}

@Nullable
private static SpecificHaxeClassReference resolveSuperclassElement(HaxeGenericResolver scopeResolver,
HaxeModel currentElement,
Expand Down

0 comments on commit 68245a3

Please sign in to comment.