Skip to content

Commit

Permalink
allow assign from underlying type to abstract enum when assign is ins…
Browse files Browse the repository at this point in the history
…ide enum body.
  • Loading branch information
m0rkeulv committed Jul 12, 2024
1 parent 1620c88 commit 679a3d8
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.intellij.plugins.haxe.util.HaxeResolveUtil;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import lombok.CustomLog;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -222,6 +223,19 @@ static public boolean canAssignToFrom(
if (classReference.isEnumValueClass()) return true; // all enum values can be assigned to EnumValueClass type;
return canAssignToFromType(classReference, valueReference.getEnumClass());
}
} else {
//NOTE: special case for abstract enums
// check if from value is same type as abstract enums underlying type and allow assign if done inside abstract enum definition
HaxeClass haxeClass = classReference.getHaxeClass();
if (haxeClass != null && haxeClass.isEnum() && haxeClass.isAbstractType()) {
if (from instanceof SpecificHaxeClassReference reference) {
PsiElement commonParent = PsiTreeUtil.findCommonParent(reference.context, haxeClass);
if (commonParent == haxeClass) {
SpecificTypeReference underlyingType = haxeClass.getModel().getUnderlyingType();
return canAssignToFrom(underlyingType, from);
}
}
}
}
}

Expand Down

0 comments on commit 679a3d8

Please sign in to comment.