Skip to content

Commit

Permalink
Fully resolve before compare compatible types, ignore OR operator err…
Browse files Browse the repository at this point in the history
…or for enum values
  • Loading branch information
m0rkeulv committed Feb 4, 2024
1 parent 4a31501 commit cde7ecb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public static void check(final HaxeBinaryExpression binaryExpression, final Anno
if (lhsType.isUnknown() || lhsType.isDynamic() || rhsType.isUnknown() || rhsType.isDynamic() || containsMacroExpression) {
return;
}

// ignoring enums as they are often "OR-ed" (|) in switch expressions (and EnumValue.match)
if (lhsType.isEnum() && rhsType.isEnum()) {
return;
}
String operatorText = children[1].getText();
String error = "Unable to apply operator " + operatorText + " for types " + lhsType.getType() + " and " + rhsType.getType();
holder.newAnnotation(HighlightSeverity.ERROR, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,19 @@ static private boolean canAssignToFromType(
Set<SpecificHaxeClassReference> compatibleTypes = to.getCompatibleTypes(SpecificHaxeClassReference.Compatibility.ASSIGNABLE_FROM);
if (to.isAbstractType() && includeImplicitCast) compatibleTypes.addAll(to.getHaxeClassModel().getImplicitCastFromTypesListClassOnly(to));
for (SpecificHaxeClassReference compatibleType : compatibleTypes) {
if (canAssignToFromSpecificType(compatibleType, from)) return true;
SpecificTypeReference compatibleTypeResolved = compatibleType.fullyResolveTypeDefAndUnwrapNullTypeReference();
if (compatibleTypeResolved instanceof SpecificHaxeClassReference classReference) {
if (canAssignToFromSpecificType(classReference, from)) return true;
}
}

compatibleTypes = from.getCompatibleTypes(SpecificHaxeClassReference.Compatibility.ASSIGNABLE_TO);
if (from.isAbstractType() && includeImplicitCast) compatibleTypes.addAll(from.getHaxeClassModel().getImplicitCastToTypesListClassOnly(from));
for (SpecificHaxeClassReference compatibleType : compatibleTypes) {
if (canAssignToFromSpecificType(to, compatibleType)) return true;
SpecificTypeReference compatibleTypeResolved = compatibleType.fullyResolveTypeDefAndUnwrapNullTypeReference();
if (compatibleTypeResolved instanceof SpecificHaxeClassReference classReference) {
if (canAssignToFromSpecificType(to, classReference)) return true;
}
}

compatibleTypes = from.getInferTypes();
Expand Down

0 comments on commit cde7ecb

Please sign in to comment.