From cde7ecb86144fb50d56523890d354a8ff2f25857 Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Sun, 4 Feb 2024 22:28:26 +0100 Subject: [PATCH] Fully resolve before compare compatible types, ignore OR operator error for enum values --- .../semantics/HaxeBinaryExpressionAnnotator.java | 5 ++++- .../plugins/haxe/model/type/HaxeTypeCompatible.java | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeBinaryExpressionAnnotator.java b/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeBinaryExpressionAnnotator.java index ad31b3306..e44426591 100644 --- a/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeBinaryExpressionAnnotator.java +++ b/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeBinaryExpressionAnnotator.java @@ -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) diff --git a/src/main/java/com/intellij/plugins/haxe/model/type/HaxeTypeCompatible.java b/src/main/java/com/intellij/plugins/haxe/model/type/HaxeTypeCompatible.java index c8b1c8068..cf0e21909 100644 --- a/src/main/java/com/intellij/plugins/haxe/model/type/HaxeTypeCompatible.java +++ b/src/main/java/com/intellij/plugins/haxe/model/type/HaxeTypeCompatible.java @@ -449,13 +449,19 @@ static private boolean canAssignToFromType( Set 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();