From 02a66c3a450d997f1e3903691b676dfa1fe065ff Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Mon, 5 Jun 2023 23:19:16 +0200 Subject: [PATCH] skipping `canAssign` check when resolving without a holder object in context --- .../ide/annotator/HaxeStandardAnnotation.java | 4 ++-- .../model/type/HaxeExpressionEvaluator.java | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/intellij/plugins/haxe/ide/annotator/HaxeStandardAnnotation.java b/src/main/java/com/intellij/plugins/haxe/ide/annotator/HaxeStandardAnnotation.java index 8c9453f02..b516120e3 100644 --- a/src/main/java/com/intellij/plugins/haxe/ide/annotator/HaxeStandardAnnotation.java +++ b/src/main/java/com/intellij/plugins/haxe/ide/annotator/HaxeStandardAnnotation.java @@ -30,13 +30,13 @@ public class HaxeStandardAnnotation { private HaxeStandardAnnotation() {} - public static @NotNull AnnotationBuilder typeMismatch(AnnotationHolder holder, PsiElement incompatibleElement, String incompatibleType, String correctType) { + public static @NotNull AnnotationBuilder typeMismatch(@NotNull AnnotationHolder holder,@NotNull PsiElement incompatibleElement, String incompatibleType, String correctType) { String message = HaxeBundle.message("haxe.semantic.incompatible.type.0.should.be.1", incompatibleType, correctType); return holder.newAnnotation(HighlightSeverity.ERROR,message).range(incompatibleElement.getTextRange()); } - public static @NotNull AnnotationBuilder returnTypeMismatch(AnnotationHolder holder, PsiElement incompatibleElement, String incompatibleType, String correctType) { + public static @NotNull AnnotationBuilder returnTypeMismatch(@NotNull AnnotationHolder holder, @NotNull PsiElement incompatibleElement, String incompatibleType, String correctType) { String message = HaxeBundle.message("haxe.semantic.incompatible.return.type.0.should.be.1", incompatibleType, correctType); return holder.newAnnotation(HighlightSeverity.ERROR, message).range(incompatibleElement.getTextRange()); } diff --git a/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java b/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java index dfcead6d1..4a242fbb2 100644 --- a/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java +++ b/src/main/java/com/intellij/plugins/haxe/model/type/HaxeExpressionEvaluator.java @@ -279,15 +279,21 @@ public void run() { final SpecificTypeReference rightValue = rightResult.getType(); //leftValue.mutateConstantValue(null); - if (!leftResult.canAssign(rightResult)) { - List fixers = HaxeExpressionConversionFixer.createStdTypeFixers(right, rightValue, leftValue); - AnnotationBuilder builder = HaxeStandardAnnotation.typeMismatch(context.holder, right, rightValue.toStringWithoutConstant(), - leftValue.toStringWithoutConstant()) - .withFix(new HaxeCastFixer(right, rightValue, leftValue)); - fixers.forEach(builder::withFix); - builder.create(); + // skipping `canAssign` check if we dont have a holder to add annotations to + // this is probably just waste of time when resolving in files we dont have open. + // TODO try to see if we need this or can move it so its not executed unnessesary + if (context.holder != null) { + if (!leftResult.canAssign(rightResult)) { + List fixers = HaxeExpressionConversionFixer.createStdTypeFixers(right, rightValue, leftValue); + AnnotationBuilder builder = HaxeStandardAnnotation + .typeMismatch(context.holder, right, rightValue.toStringWithoutConstant(), leftValue.toStringWithoutConstant()) + .withFix(new HaxeCastFixer(right, rightValue, leftValue)); + + fixers.forEach(builder::withFix); + builder.create(); + } } if (leftResult.isImmutable()) {